Skip to content

Commit

Permalink
correct the review
Browse files Browse the repository at this point in the history
  • Loading branch information
Olga-koml committed Nov 17, 2023
1 parent 583fc22 commit af128af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
21 changes: 11 additions & 10 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,18 @@ def create(self, validated_data):

def update(self, instance, validated_data):
status_approve = instance.status_approve
if (
status_approve != Project.EDITING
and status_approve != Project.REJECTED
):
if status_approve not in (Project.EDITING, Project.REJECTED):
raise serializers.ValidationError(
'Сохранять как черновик можно проекты '
'со статусом "Editing" или "Rejected".'
f'со статусом {Project.EDITING} или {Project.REJECTED}.'
)
address_data = validated_data.pop('event_address', None)
if address_data:
address = instance.event_address
for attr, value in address_data.items():
setattr(address, attr, value)
address.save()
if address:
for attr, value in address_data.items():
setattr(address, attr, value)
address.save()
return super().update(instance, validated_data)

class Meta:
Expand All @@ -302,8 +300,11 @@ class Meta:
'skills',
)
read_only_fields = ('organization',)
extra_kwargs = {'status_approve': {'required': False},
'categories': {'required': False, 'allow_empty': True}}
extra_kwargs = {
'status_approve': {'required': False},
'categories': {'required': False, 'allow_empty': True},
'event_address': {'required': False, 'allow_empty': True}
}


class ProjectSerializer(serializers.ModelSerializer):
Expand Down
12 changes: 6 additions & 6 deletions backend/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def is_correct_status_change(status_before, status_new):
"""

allowed_status_changes = {
Project.EDITING: [Project.EDITING, Project.PENDING],
Project.PENDING: [Project.APPROVED, Project.REJECTED],
Project.REJECTED: [Project.EDITING, Project.PENDING],
Project.APPROVED: [Project.APPROVED, Project.CANCELED_BY_ORGANIZER],
# Project.CANCELED_BY_ORGANIZER: [Project.EDITING], # Может измениться
Project.EDITING: (Project.EDITING, Project.PENDING),
Project.PENDING: (Project.APPROVED, Project.REJECTED),
Project.REJECTED: (Project.EDITING, Project.PENDING),
Project.APPROVED: (Project.APPROVED, Project.CANCELED_BY_ORGANIZER),
# Project.CANCELED_BY_ORGANIZER: [Project.EDITING], # Может изменится
}
return status_new in allowed_status_changes.get(status_before, [])
return status_new in allowed_status_changes.get(status_before, ())


class NonEmptyBase64ImageField(Base64ImageField):
Expand Down

0 comments on commit af128af

Please sign in to comment.