Skip to content

Commit

Permalink
do not check for book and contact on resource creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mwvolo committed Dec 13, 2023
1 parent 58d35b3 commit d5e42a6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions salesforce/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,16 @@ def create(self, validated_data):
resource_name = validated_data.get('resource_name', None)
contact_id = validated_data.get('contact_id', None)
rd = []
if book and contact_id:
try:
rd = ResourceDownload.objects.filter(account_uuid=account_uuid, book=book)
if resource_name:
rd.filter(resource_name=resource_name)

rd = rd[0] # we only need the first result - but there might already be duplicates so this should handle that
rd.contact_id = contact_id
rd.save()
except (ResourceDownload.DoesNotExist, IndexError):
rd = ResourceDownload.objects.create(**validated_data)
try:
rd = ResourceDownload.objects.filter(account_uuid=account_uuid, book=book)
if resource_name:
rd.filter(resource_name=resource_name)

rd = rd.first
rd.contact_id = contact_id
rd.save()
except (ResourceDownload.DoesNotExist, IndexError):
rd = ResourceDownload.objects.create(**validated_data)

return rd

Expand Down

0 comments on commit d5e42a6

Please sign in to comment.