Skip to content

Commit

Permalink
Merge pull request #386 from Pet-projects-CodePET/fix/requests_and_in…
Browse files Browse the repository at this point in the history
…vitations

fix: Исправил проблему в коде, по валидации позиции
  • Loading branch information
Denis-Shtanskiy authored Oct 2, 2024
2 parents c97adae + 0f7b964 commit dba64ce
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/backend/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ def validate_project(self, value):
"""

user = self.context.get("request").user
print(f"Здесь мы посмотрим на значение {value}")
project = (
Project.objects.filter(id=value.id)
.select_related(
Expand Down Expand Up @@ -399,14 +400,22 @@ def validate_position(self, value):
Метод, проверяет, является ли позиция валидной для данного проекта.
"""

project = self.context.get("project")
project_id = self.initial_data.get("project")
if project_id is None:
raise serializers.ValidationError("Проект не найден.")
try:
project = Project.objects.get(pk=project_id)
except Project.DoesNotExist:
raise serializers.ValidationError("Проект не найден.")
print(f"Посмотреть {value.id}")
project_specialists = project.project_specialists.all()
if not any(
specialist.profession.name == value and specialist.is_required
specialist.profession.id == value.id and specialist.is_required
for specialist in project_specialists
):
raise serializers.ValidationError(
f"Позиция '{value}' не требуется в проекте '{project.name}'."
f"Специальность '{value.profession.specialization}' "
f"не требуется в проекте '{project.name}'."
)
return value

Expand All @@ -433,9 +442,6 @@ def validate(self, attrs) -> Dict[str, Any]:
f"Вас уже существует и находится в статусе "
f"'{participation_request.get_status_display()}'."
)

self.validate_position(attrs["position"])

if errors:
raise serializers.ValidationError(errors)
return attrs
Expand Down

0 comments on commit dba64ce

Please sign in to comment.