From ff8dd0b93be7cb3154c9a687d2aee8aedf5fbb23 Mon Sep 17 00:00:00 2001 From: kvn <42082827+crypto-rizzo@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:39:14 -0400 Subject: [PATCH] slight refactor - remove customer_name (not needed / more friction) - update / simplify rsvp forloop accordingly --- backend/apps/dashboard_organizer/forms.py | 5 -- backend/apps/dashboard_organizer/views.py | 46 +++++++------------ .../rsvp_create_tickets.html | 9 +--- 3 files changed, 18 insertions(+), 42 deletions(-) diff --git a/backend/apps/dashboard_organizer/forms.py b/backend/apps/dashboard_organizer/forms.py index c2fc1272b..ca76f316a 100644 --- a/backend/apps/dashboard_organizer/forms.py +++ b/backend/apps/dashboard_organizer/forms.py @@ -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={ diff --git a/backend/apps/dashboard_organizer/views.py b/backend/apps/dashboard_organizer/views.py index 28cbde51a..db4df82f6 100644 --- a/backend/apps/dashboard_organizer/views.py +++ b/backend/apps/dashboard_organizer/views.py @@ -1156,43 +1156,23 @@ 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"], @@ -1200,8 +1180,14 @@ def form_valid(self, form, **kwargs): 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) diff --git a/backend/templates/redesign/dashboard_organizer/rsvp_create_tickets.html b/backend/templates/redesign/dashboard_organizer/rsvp_create_tickets.html index 9456ea6ce..e657dee2f 100644 --- a/backend/templates/redesign/dashboard_organizer/rsvp_create_tickets.html +++ b/backend/templates/redesign/dashboard_organizer/rsvp_create_tickets.html @@ -49,15 +49,10 @@

{% trans "Ticket Tier" %}



-

{% trans "Customer Names and Emails" %}

+

{% trans "Customer Emails" %}

- {% 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)." %}

-
- {% with form.customer_names as input %} - {% include "redesign/forms/input.html" %} - {% endwith %} -
{% with form.customer_emails as input %} {% include "redesign/forms/input.html" %}