Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PATCH request for completer and canseled by org projects #252

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,15 @@ def validate_skills(self, value):
return value

def validate(self, data):
start_datetime = data['start_datetime']
end_datetime = data['end_datetime']
start_date_application = data['start_date_application']
end_date_application = data['end_date_application']
try:
start_datetime = data['start_datetime']
end_datetime = data['end_datetime']
start_date_application = data['start_date_application']
end_date_application = data['end_date_application']
except KeyError as field:
raise serializers.ValidationError(
f'{self.__class__.__name__}: Передайте в запросе поле {field}'
)
try:
validate_dates(
start_datetime,
Expand Down Expand Up @@ -462,6 +467,13 @@ class Meta(ProjectSerializer.Meta):
'skills',
)

def validate(self, data):
status_approve = data.get('status_approve')
if status_approve == 'canceled_by_organizer':
return data
else:
return super().validate(data)


class ProjectCompleteSerializer(ProjectSerializer):
"""
Expand All @@ -481,8 +493,10 @@ class Meta(ProjectSerializer.Meta):
fields = ProjectSerializer.Meta.fields + ('photos', 'uploaded_photos',)
read_only_fields = ProjectSerializer.Meta.fields

# если зазгрузка фоток не обязательная, иначе убрать if uploaded_data:
def validate(self, data):
return data

# если зазгрузка фоток не обязательная, иначе убрать if uploaded_data:
def update(self, instance, validated_data):
uploaded_data = validated_data.pop('uploaded_photos', None)
instance.photos.all().delete()
Expand Down