diff --git a/banquet/functions.py b/banquet/functions.py index 97f159ab..b52afd4e 100644 --- a/banquet/functions.py +++ b/banquet/functions.py @@ -22,7 +22,7 @@ def send_invitation_mail(request, invitation, name, date, location, link, email, ) except Exception as e: print("Failed to send email: ", e) - return + raise e invitation.has_sent_mail = True invitation.save() diff --git a/banquet/views.py b/banquet/views.py index f2f21d23..2e9728c3 100644 --- a/banquet/views.py +++ b/banquet/views.py @@ -604,6 +604,7 @@ def manage_map(request, year, banquet_pk): def manage_invitations(request, year, banquet_pk): fair = get_object_or_404(Fair, year=year) banquet = get_object_or_404(Banquet, fair=fair, pk=banquet_pk) + did_error_email = request.GET.get("did_error_email", False) invitations = [] @@ -627,6 +628,7 @@ def manage_invitations(request, year, banquet_pk): "price": invitation.price, "deadline_smart": invitation.deadline_smart, "matching_status": invitation.part_of_matching, + "has_sent_mail": invitation.has_sent_mail, } ) @@ -686,6 +688,7 @@ def manage_invitations(request, year, banquet_pk): "banquet": banquet, "invitiations": invitations_modified, "form": form, + "did_error_email": did_error_email, }, ) @@ -734,6 +737,8 @@ def manage_import_invitations(request, year, banquet_pk): "You must select a group to invite to the banquet.", ) else: + did_error_email = False + for invite in imported: # Invite already exists if Invitation.objects.filter( @@ -752,17 +757,27 @@ def manage_import_invitations(request, year, banquet_pk): invitation.save() if send_mail: - send_confirmation_email( - request, invitation, invite["name"], invite["email"], fair - ) + try: + send_confirmation_email( + request, + invitation, + invite["name"], + invite["email"], + fair, + ) + except Exception as e: + did_error_email = True + continue invitation.has_sent_mail = True invitation.save() return redirect( - "banquet_manage_invitations", - fair.year, - banquet.pk, + reverse( + "banquet_manage_invitations", + kwargs={"year": year, "banquet_pk": banquet.pk}, + ) + + ("?did_error_email=1" if did_error_email else "") ) return render( diff --git a/templates/banquet/manage_invitations.html b/templates/banquet/manage_invitations.html index a3dafaba..1f4a1e84 100644 --- a/templates/banquet/manage_invitations.html +++ b/templates/banquet/manage_invitations.html @@ -7,6 +7,18 @@ {% endblock %} {% block content %} + {% if did_error_email %} +