Skip to content

Commit

Permalink
add to populate script
Browse files Browse the repository at this point in the history
  • Loading branch information
rohangpta committed Nov 12, 2022
1 parent 7baf414 commit bf35552
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
34 changes: 33 additions & 1 deletion backend/clubs/management/commands/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ApplicationQuestion,
ApplicationSubmission,
Badge,
Cart,
Club,
ClubApplication,
ClubFair,
Expand All @@ -28,6 +29,7 @@
StudentType,
Tag,
Testimonial,
Ticket,
Year,
)

Expand Down Expand Up @@ -662,7 +664,10 @@ def get_image(url):
status_counter % len(ApplicationSubmission.STATUS_TYPES)
][0]
ApplicationSubmission.objects.create(
status=status, user=user, application=application, committee=None,
status=status,
user=user,
application=application,
committee=None,
)
status_counter += 1
for committee in application.committees.all():
Expand Down Expand Up @@ -746,4 +751,31 @@ def get_image(url):
first_mship.save()
count += 1

# add tickets

hr = Club.objects.get(code="harvard-rejects")

hr_events = Event.objects.filter(club=hr)

for idx, e in enumerate(hr_events[:3]):
# Switch up person every so often
person = ben if idx < 2 else user_objs[1]

# Create some unowned tickets
Ticket.objects.bulk_create(
[Ticket(event=e, type="Regular") for _ in range(10)]
)

Ticket.objects.bulk_create(
[Ticket(event=e, type="Premium") for _ in range(5)]
)

# Create some owned tickets and tickets in cart
for i in range((idx + 1) * 10):
if i % 5:
Ticket.objects.create(event=e, owner=person, type="Regular")
else:
c, _ = Cart.objects.get_or_create(owner=person)
c.tickets.add(Ticket.objects.create(event=e, type="Premium"))

self.stdout.write("Finished populating database!")
5 changes: 4 additions & 1 deletion backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,8 @@ def tickets(self, request, *args, **kwargs):
@transaction.atomic
def create_tickets(self, request, *args, **kwargs):
"""
Create ticket offerings for event
---
requestBody:
content:
application/json:
Expand All @@ -2456,12 +2458,13 @@ def create_tickets(self, request, *args, **kwargs):
content:
application/json:
schema:
type: object
properties:
detail:
type: string
---
"""
event = self.get_object()

quantities = request.data.get("quantities")

# Atomicity ensures idempotency
Expand Down

0 comments on commit bf35552

Please sign in to comment.