Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add email sent column #1273

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading