Skip to content

Commit

Permalink
feat: Add feature to resend emails (#1278)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes: #
  • Loading branch information
didrikmunther authored Oct 5, 2024
1 parent 787e89e commit abef520
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 22 deletions.
5 changes: 5 additions & 0 deletions banquet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
views.manage_import_invitations,
name="banquet_import_invitations",
),
url(
r"^(?P<banquet_pk>[0-9]+)/email$",
views.manage_handle_email,
name="banquet_handle_email",
),
url(
r"^(?P<banquet_pk>[0-9]+)/participants$",
views.manage_participants,
Expand Down
82 changes: 61 additions & 21 deletions banquet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,60 @@ def manage_invitation(request, year, banquet_pk, invitation_pk):
)


@permission_required("banquet.base")
def manage_handle_email(request, year, banquet_pk):
fair = get_object_or_404(Fair, year=year)
banquet = get_object_or_404(Banquet, fair=fair, pk=banquet_pk)
invitations = Invitation.objects.filter(banquet=banquet, has_sent_mail=False)

if request.POST:
did_error_email = False

for invitation in invitations:
invitation.save()

print(
invitation,
invitation.name,
invitation.email_address,
fair,
)

if not send_confirmation_email(
request,
invitation,
invitation.name,
invitation.email_address,
fair,
):
did_error_email = True
continue

invitation.has_sent_mail = True
invitation.save()

return redirect(
reverse(
"banquet_handle_email",
kwargs={"year": year, "banquet_pk": banquet_pk},
)
+ ("?did_error_email=1" if did_error_email else "")
)

print(invitations)

return render(
request,
"banquet/manage_handle_email.html",
{
"fair": fair,
"banquet": banquet,
"did_error_email": request.GET.get("did_error_email", False),
"invitations": invitations,
},
)


@permission_required("banquet.base")
def manage_import_invitations(request, year, banquet_pk):
fair = get_object_or_404(Fair, year=year)
Expand Down Expand Up @@ -757,15 +811,13 @@ def manage_import_invitations(request, year, banquet_pk):
invitation.save()

if send_mail:
try:
send_confirmation_email(
request,
invitation,
invite["name"],
invite["email"],
fair,
)
except Exception as e:
if not send_confirmation_email(
request,
invitation,
invite["name"],
invite["email"],
fair,
):
did_error_email = True
continue

Expand Down Expand Up @@ -1227,18 +1279,6 @@ def send_invitation_button(request, year, banquet_pk, invitation_pk):
)
)

print(
"Sending invitation mail",
{
"invitation": invitation,
"name": name,
"banquet.date": banquet.date,
"banquet.location": banquet.location,
"link": link,
"email": email,
},
)

if send_invitation_mail(
request,
invitation,
Expand Down
120 changes: 120 additions & 0 deletions templates/banquet/manage_handle_email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{% extends "base.html" %}

{% load crispy_forms_tags %}

{% block nav-banquet %}
<li role="presentation" class="active"><a href="{% url 'banquet_dashboard' fair.year %}">Banquet</a></li>
{% 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!</h1>
{% endif %}

<h1>{{ banquet.name }} – Unsent Email</h1>

<div style="margin-bottom: 10px; display: flex; justify-content: space-between;">
<div>
<a class="btn btn-default" href="{% url 'banquet_manage_invitations' fair.year banquet.pk %}">Invitations</a>
<a class="btn btn-default" href="{% url 'banquet_manage_participants' fair.year banquet.pk %}">Participants</a>
</div>
<div>
<form method="post">
{% csrf_token %}
<button class="btn btn-danger">Send emails</button>
</form>
</div>
</div>

<style type="text/css">
.form_no_ul ul
{
margin: 0;
padding: 0;
margin: 0 0 20px 15px;
}

.form_no_ul ul li
{
list-style-type: none;
}

.form_no_ul ul li label
{
font-weight: 400;
}
</style>

<div class="table-responsive">
<table class="table" id="invitation_table">
<thead>
<tr>
<th>Group</th>
<th>Deadline</th>
<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>
</thead>

<tbody>
{% for invitation in invitations %}
<tr>
<td>{{ invitation.group }}</td>
<td>{% if invitation.deadline_smart is not None %} <span style="display: none;">{{ invitation.deadline_smart|date:"U" }}</span> {{ invitation.deadline_smart }} {% else %} <span style="font-style: italic;">no deadline</span> {% endif %}</td>
<td>
{% if invitation.user %} <a href="{% url 'people:profile' fair.year invitation.user.pk %}">{{ invitation.name }}</a> {% else %} {{ invitation.name }} {% endif %}

{% if invitation.status == 'GOING' %}<span class="label label-success">Going</span>{% endif %}
{% if invitation.status == 'HAS_NOT_PAID' %}<span class="label label-warning">Has not paid</span>{% endif %}
{% if invitation.status == 'NOT_GOING' %}<span class="label label-danger">Not going</span>{% endif %}
{% if invitation.status == 'PENDING' %}<span class="label label-default">Pending</span>{% endif %}
</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>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}

{% block scripts %}
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<script>
$(function()
{
$('#invitation_table').DataTable(
{
'paging': false,
"columns":
[
null,
null,
null,
null,
null,
null,
null,
{ 'orderable': false }
]
});
})
</script>
{% endblock %}
3 changes: 2 additions & 1 deletion templates/banquet/manage_invitations.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
padding: 15px;
border: 1px solid transparent;
border-radius: 4px;
">Failed to send some emails! Need to check manually</h1>
">Failed to send some emails!</h1>
{% endif %}

<h1>{{ banquet.name }} – Invitations</h1>
Expand All @@ -28,6 +28,7 @@ <h1>{{ banquet.name }} – Invitations</h1>
{% if banquet.background %} <a class="btn btn-default" href="{% url 'banquet_manage_map' fair.year banquet.pk %}">Map</a> {% endif %}
</div>
<div>
<a class="btn btn-default" href="{% url 'banquet_handle_email' fair.year banquet.pk %}">Handle Emails</a>
<a class="btn btn-default" href="{% url 'banquet_import_invitations' fair.year banquet.pk %}">Import invitations</a>
<a class="btn btn-default" href="{% url 'banquet_manage_invitation_new' fair.year banquet.pk %}">New invitation</a>
</div>
Expand Down

0 comments on commit abef520

Please sign in to comment.