diff --git a/program/serializers.py b/program/serializers.py index d5107d0c0ebc2537d87aca0b5a163fff39b0256f..1c407c918bd0dd380aad8871df01c2c15fd4ef70 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -381,21 +381,18 @@ class HostSerializer(serializers.ModelSerializer): raise exceptions.PermissionDenied(detail="You are not allowed to update this host.") # Only users with edit permissions are allowed to edit these fields - if ( - biography := validated_data.get("biography") - ) and "biography" not in user_edit_permissions: + if "biography" in validated_data and "biography" not in user_edit_permissions: raise exceptions.PermissionDenied( detail="You are not allowed to edit the host’s biography." ) - else: - instance.biography = biography - if (name := validated_data.get("name")) and "name" not in user_edit_permissions: + if "name" in validated_data and "name" not in user_edit_permissions: raise exceptions.PermissionDenied( detail="You are not allowed to edit the host’s name." ) - else: - instance.name = name + + instance.biography = validated_data.get("biography", instance.biography) + instance.name = validated_data.get("name", instance.name) # Only update these fields if the user is privileged, ignore otherwise if user_is_privileged: @@ -606,30 +603,27 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): raise exceptions.PermissionDenied(detail="You are not allowed to update this show.") # Only users with edit permissions are allowed to update these fields - if ( - description := validated_data.get("description") - ) and "description" not in user_edit_permissions: + if "description" in validated_data and "description" not in user_edit_permissions: raise exceptions.PermissionDenied( detail="You are not allowed to edit the show’s description." ) - else: - instance.description = description - if (name := validated_data.get("name")) and "name" not in user_edit_permissions: + if "name" in validated_data and "name" not in user_edit_permissions: raise exceptions.PermissionDenied( detail="You are not allowed to edit the show’s name." ) - else: - instance.name = name if ( - short_description := validated_data.get("short_description") - ) and "short_description" not in user_edit_permissions: + "short_description" in validated_data + and "short_description" not in user_edit_permissions + ): raise exceptions.PermissionDenied( detail="You are not allowed to edit the show’s short description." ) - else: - instance.short_description = short_description + + instance.description = validated_data.get("description", instance.description) + instance.name = validated_data.get("name", instance.name) + instance.short_description = validated_data.get("name", instance.name) # Only update these fields if the user is privileged, ignore otherwise if user_is_privileged: @@ -642,7 +636,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): "funding_category_id", instance.funding_category ) instance.image = validated_data.get("image_id", instance.image) - instance.internal_note = validated_data.get("interna_note", instance.internal_note) + instance.internal_note = validated_data.get("internal_note", instance.internal_note) instance.is_active = validated_data.get("is_active", instance.is_active) instance.is_public = validated_data.get("is_public", instance.is_public) instance.logo = validated_data.get("logo", instance.logo)