Skip to content

Commit

Permalink
atomic transactions, cleanup, and some views
Browse files Browse the repository at this point in the history
  • Loading branch information
rohangpta committed Oct 2, 2022
1 parent 74183d4 commit 989b032
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 98 deletions.
20 changes: 15 additions & 5 deletions backend/clubs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,9 @@ class ApplicationCommittee(models.Model):

name = models.TextField(blank=True)
application = models.ForeignKey(
ClubApplication, related_name="committees", on_delete=models.CASCADE,
ClubApplication,
related_name="committees",
on_delete=models.CASCADE,
)

def get_word_limit(self):
Expand Down Expand Up @@ -1626,7 +1628,9 @@ class ApplicationMultipleChoice(models.Model):

value = models.TextField(blank=True)
question = models.ForeignKey(
ApplicationQuestion, related_name="multiple_choice", on_delete=models.CASCADE,
ApplicationQuestion,
related_name="multiple_choice",
on_delete=models.CASCADE,
)


Expand Down Expand Up @@ -1707,7 +1711,7 @@ class Cart(models.Model):
Represents an instance of a ticket cart for a user
"""

owner = models.ForeignKey(
owner = models.OneToOneField(
get_user_model(), related_name="cart", on_delete=models.CASCADE
)

Expand All @@ -1724,12 +1728,18 @@ class Ticket(models.Model):
type = models.CharField(max_length=100)
owner = models.ForeignKey(
get_user_model(),
related_name="tickets",
related_name="owned_tickets",
on_delete=models.SET_NULL,
blank=True,
null=True,
)
holder = models.ForeignKey(
get_user_model(),
related_name="held_tickets",
on_delete=models.SET_NULL,
blank=True,
null=True,
)
held = models.BooleanField(default=False)
holding_expiration = models.DateTimeField(null=True, blank=True)
carts = models.ManyToManyField(Cart, related_name="tickets", blank=True)

Expand Down
14 changes: 11 additions & 3 deletions backend/clubs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,12 @@ class ClubEventSerializer(serializers.ModelSerializer):
image_url = serializers.SerializerMethodField("get_image_url")
large_image_url = serializers.SerializerMethodField("get_large_image_url")
url = serializers.SerializerMethodField("get_event_url")
ticketed = serializers.SerializerMethodField("get_ticketed")
creator = serializers.HiddenField(default=serializers.CurrentUserDefault())

def get_ticketed(self, obj):
return Event.tickets.exists()

def get_event_url(self, obj):
# if no url, return that
if not obj.url:
Expand Down Expand Up @@ -2007,7 +2011,9 @@ def get_clubs(self, obj):
# hide non public memberships if not superuser
if user is None or not user.has_perm("clubs.manage_club"):
queryset = queryset.filter(
membership__person=obj, membership__public=True, approved=True,
membership__person=obj,
membership__public=True,
approved=True,
)

serializer = MembershipClubListSerializer(
Expand Down Expand Up @@ -2408,7 +2414,8 @@ def save(self):
ApplicationMultipleChoice.objects.filter(question=question_obj).delete()
for choice in multiple_choice:
ApplicationMultipleChoice.objects.create(
value=choice["value"], question=question_obj,
value=choice["value"],
question=question_obj,
)

# manually create committee choices as Django does not
Expand Down Expand Up @@ -2697,7 +2704,8 @@ def save(self):
for name in committees:
if name not in prev_committee_names:
ApplicationCommittee.objects.create(
name=name, application=application_obj,
name=name,
application=application_obj,
)

return application_obj
Expand Down
Loading

0 comments on commit 989b032

Please sign in to comment.