Skip to content

Commit

Permalink
Add email sent column
Browse files Browse the repository at this point in the history
  • Loading branch information
didrikmunther committed Sep 23, 2024
1 parent 28a1fbe commit f58f5fa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion banquet/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 21 additions & 6 deletions banquet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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,
}
)

Expand Down Expand Up @@ -686,6 +688,7 @@ def manage_invitations(request, year, banquet_pk):
"banquet": banquet,
"invitiations": invitations_modified,
"form": form,
"did_error_email": did_error_email,
},
)

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions templates/banquet/manage_invitations.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
{% endblock %}

{% block content %}
{% if did_error_email %}
<h1 style="
background-color: #f2dede;
border-color: #ebccd1;
color: #a94442;
margin: 0 0 20px 0;
padding: 15px;
border: 1px solid transparent;
border-radius: 4px;
">Failed to send some emails! Need to check manually</h1>
{% endif %}

<h1>{{ banquet.name }} – Invitations</h1>

<div style="margin-bottom: 10px; display: flex; justify-content: space-between;">
Expand Down Expand Up @@ -72,6 +84,7 @@ <h1>{{ banquet.name }} – Invitations</h1>
<th>Name</th>
<th>Reason</th>
<th>Part of Matching</th>
<th>Email sent</th>
<th style="text-align: right; white-space: nowrap;">Price (SEK)</th>
<th></th>
</tr>
Expand All @@ -92,6 +105,7 @@ <h1>{{ banquet.name }} – Invitations</h1>
</td>
<td>{% if invitation.reason %}{{ invitation.reason }}{% endif %}</td>
<td>{% if invitation.matching_status %} Yes {% else %} No {% endif %}</td>
<td>{% if invitation.has_sent_mail %} Yes {% else %} No {% endif %}</td>
<td style="text-align: right;">{{ invitation.price }}</td>
<td style="text-align: right;"><a href="{% url 'banquet_manage_invitation' fair.year banquet.pk invitation.pk %}" class="btn btn-sm btn-default">Details</a></td>
</tr>
Expand Down Expand Up @@ -119,6 +133,7 @@ <h1>{{ banquet.name }} – Invitations</h1>
null,
null,
null,
null,
{ 'orderable': false }
]
});
Expand Down

0 comments on commit f58f5fa

Please sign in to comment.