Skip to content

Commit

Permalink
Merge pull request #10 from rosiemaguire/Issue_1/Project_open_closed_…
Browse files Browse the repository at this point in the history
…restrictions

Issue 1/project open closed restrictions
  • Loading branch information
rosiejeays committed Sep 2, 2023
2 parents 8769d13 + f237e8c commit 9468d4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ This project is the back end of a crowdfunding website which has been created to

- [X] Pledge put request does not allow any modification of which project it is attached to
- [X] Pledges cannot be created or modified for projects that are set to closed
- [ ] Project owner only able to update open/closed field if project has been set to closed
- [X] Project owner only able to update open/closed and deleted field if project has been set to closed
- [ ] Validation to ensure at least one field is modified in PUT Request (rather than just updating the last_modified date because PUT request fields are identical to data in table)
- [X] Users able to "soft delete" projects and pledges they own (e.g. set deleted field to 1 which hides in front end) own pledges/projects
- [ ] Put restrictions around user creation
Expand Down
29 changes: 17 additions & 12 deletions crowdfunding/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ class ProjectDetailSerializer(ProjectSerializer):
pledges = PledgeSerializer(many=True)

def update(self,instance,validated_data):
instance.title = validated_data.get('title', instance.title)
instance.description = validated_data.get('description', instance.description)
instance.goal = validated_data.get('goal', instance.goal)
instance.image = validated_data.get('image', instance.image)
instance.is_open = validated_data.get('is_open', instance.is_open)
instance.is_deleted = validated_data.get('is_deleted', instance.is_deleted)
if instance.is_deleted == True:
instance.is_open = False
for pledge in instance.pledges.all():
pledge.is_deleted = True
pledge.save()
instance.save()
if instance.is_open:
instance.title = validated_data.get('title', instance.title)
instance.description = validated_data.get('description', instance.description)
instance.goal = validated_data.get('goal', instance.goal)
instance.image = validated_data.get('image', instance.image)
instance.is_open = validated_data.get('is_open', instance.is_open)
instance.is_deleted = validated_data.get('is_deleted', instance.is_deleted)
if instance.is_deleted == True:
instance.is_open = False
for pledge in instance.pledges.all():
pledge.is_deleted = True
pledge.save()
instance.save()
else:
instance.is_open = validated_data.get('is_open',instance.is_open)
instance.is_deleted = validated_data.get('is_deleted', instance.is_deleted)
instance.save()
return instance

class PledgeDetailSerializer(PledgeSerializer):
Expand Down

0 comments on commit 9468d4b

Please sign in to comment.