Skip to content

Commit

Permalink
slight refactor
Browse files Browse the repository at this point in the history
- remove customer_name (not needed / more friction)
- update / simplify rsvp forloop accordingly
  • Loading branch information
crypto-rizzo committed Oct 21, 2023
1 parent 126a731 commit ff8dd0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 42 deletions.
5 changes: 0 additions & 5 deletions backend/apps/dashboard_organizer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,6 @@ class RSVPCreateTicketsForm(forms.Form):
Bulk tickets create form for the RSVP system.
"""
ticket_tier = forms.ModelChoiceField(queryset=TicketTier.objects.none())
customer_names = forms.CharField(
widget=forms.TextInput(
attrs={"placeholder": _("John Doe, Jane Doe, Jack Gates")}
),
)
customer_emails = forms.CharField(
widget=forms.TextInput(
attrs={
Expand Down
46 changes: 16 additions & 30 deletions backend/apps/dashboard_organizer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,52 +1156,38 @@ def get_form(self, form_class=None):
def form_valid(self, form, **kwargs):
context = self.get_context_data(**kwargs)

# Create sessons, items, and tickets manually
names = form.cleaned_data["customer_names"].split(",")
emails = form.cleaned_data["customer_emails"].split(",")

# Names and emails should be the same number
if len(names) != len(emails):
messages.add_message(
self.request,
messages.ERROR,
"Please make sure the customer names and emails are valid CSV, "
"and that each list has equal number of items."
)
return super().form_invalid(form)
# Create RSVPBatch object
rsvp_batch = RSVPBatch.objects.create(
event=context["event"],
)

# Each email should be valid
emails = form.cleaned_data["customer_emails"].split(",")
for email in emails:
try:
# Validate Email
validate_email(email.strip())
except Exception:
messages.add_message(
self.request,
messages.ERROR,
"Please make sure each email address is valid."
)
return super().form_invalid(form)

rsvp_batch = RSVPBatch.objects.create(
event=context["event"],
)
for i in range(len(names)):
try:
# Create checkout session, items, and fulfill session
with transaction.atomic():
checkout_session = CheckoutSession.objects.create(
event=context["event"],
rsvp_batch=rsvp_batch,
name=names[i].strip(),
email=emails[i].strip(),
email=email.strip(),
)
checkout_item = CheckoutItem.objects.create(
ticket_tier=form.cleaned_data["ticket_tier"],
checkout_session=checkout_session,
quantity=1,
)
checkout_session.fulfill()
except Exception:
pass
except Exception as e:
print(e)
messages.add_message(
self.request,
messages.ERROR,
"Please make sure each email address is valid."
)
return super().form_invalid(form)

return super().form_valid(form)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ <h4 class="mb-lg-4">{% trans "Ticket Tier" %}</h4>
</div>

<br /><br />
<h4>{% trans "Customer Names and Emails" %}</h4>
<h4>{% trans "Customer Emails" %}</h4>
<p class="text-body-secondary mb-lg-4">
{% trans "Please enter a list of customer names and email addresses as CSV (Comma Separated Values)." %}
{% trans "Please enter a list of customer email addresses as CSV (Comma Separated Values)." %}
</p>
<div class="mb-3">
{% with form.customer_names as input %}
{% include "redesign/forms/input.html" %}
{% endwith %}
</div>
<div class="mb-3">
{% with form.customer_emails as input %}
{% include "redesign/forms/input.html" %}
Expand Down

0 comments on commit ff8dd0b

Please sign in to comment.