Skip to content

Commit

Permalink
fix: Исправил проблему в коде, по валидации позиции
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis-Shtanskiy committed Oct 2, 2024
1 parent 8663b69 commit 0f7b964
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 @@ -367,6 +367,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 @@ -394,14 +395,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 @@ -428,9 +437,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 0f7b964

Please sign in to comment.