Skip to content

Commit

Permalink
fix: Add banquet fixes (#1272)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes: #
  • Loading branch information
didrikmunther authored Sep 23, 2024
1 parent c72ee44 commit 28a1fbe
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 33 deletions.
53 changes: 30 additions & 23 deletions banquet/functions.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from django.urls import reverse
from django.core.mail import send_mail

from util.email import send_mail

def send_invitation_mail(invitation, name, date, location, link, email):

def send_invitation_mail(request, invitation, name, date, location, link, email, fair):
"""Send banquet invitation mail"""
send_mail(
"Your invite to the banquet",
"Hello "
+ str(name)
+ "!\n"
+ "You have been invited to the Grand Banquet of THS Armada.\n"
+ "The banquet takes place "
+ str(date)
+ " at "
+ str(location)
+ ". \nAccess your invitation with the following link:\n"
+ link
+ "\n\nSee you at the banquet!\n"
+ "Best Regards,\n"
+ "The Banquet Team of THS Armada 2023",
"Armada Banquet <[email protected]>",
[email],
fail_silently=True,
)
try:
send_mail(
request,
template="banquet/email/invitation.html",
context={
"name": name,
"date": date,
"location": location,
"link": link,
"year": fair.year,
},
subject="Initial registration received!",
to=[email],
# file_paths=[settings.MEDIA_ROOT + signature.contract.contract.url[6:]],
)
except Exception as e:
print("Failed to send email: ", e)
return

invitation.has_sent_mail = True
invitation.save()


def send_confirmation_email(request, invitation, name, email_address):
def send_confirmation_email(request, invitation, name, email_address, fair):
"""Send banquet confirmation mail"""

if invitation.has_sent_mail:
Expand Down Expand Up @@ -61,5 +61,12 @@ def send_confirmation_email(request, invitation, name, email_address):
)

send_invitation_mail(
invitation, name, banquet.date, banquet.location, link, email_address
request,
invitation,
name,
banquet.date,
banquet.location,
link,
email_address,
fair,
)
16 changes: 12 additions & 4 deletions banquet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def manage_import_invitations(request, year, banquet_pk):

if send_mail:
send_confirmation_email(
request, invitation, invite["name"], invite["email"]
request, invitation, invite["name"], invite["email"], fair
)

invitation.has_sent_mail = True
Expand Down Expand Up @@ -885,7 +885,7 @@ def manage_invitation_form(request, year, banquet_pk, invitation_pk=None):

# Automatically send invite email if it hasn't been sent before
if send_mail and not has_sent_mail:
send_confirmation_email(request, invitation, name, email_address)
send_confirmation_email(request, invitation, name, email_address, fair)
form.instance.has_sent_mail = True
form.save()

Expand All @@ -907,8 +907,10 @@ def manage_participant(request, year, banquet_pk, participant_pk):
participant = get_object_or_404(Participant, banquet=banquet, pk=participant_pk)

try:
invitation_status = participant.invitation_set.first().status
invitation = participant.invitation_set.first()
invitation_status = invitation.status
except:
invitation = None
invitation_status = None

return render(
Expand All @@ -917,6 +919,7 @@ def manage_participant(request, year, banquet_pk, participant_pk):
{
"fair": fair,
"banquet": banquet,
"invitation": invitation,
"participant": {
"pk": participant.pk,
"name": (
Expand Down Expand Up @@ -1213,7 +1216,9 @@ def send_invitation_button(request, year, banquet_pk, invitation_pk):
},
)

send_invitation_mail(invitation, name, banquet.date, banquet.location, link, email)
send_invitation_mail(
request, invitation, name, banquet.date, banquet.location, link, email, fair
)

return render(
request,
Expand Down Expand Up @@ -1614,10 +1619,12 @@ def export_participants(request, year, banquet_pk):
"Seat",
"Dietary restrictions",
"Other dietary restrictions",
"Dietary preferences",
"invitation",
"checked_in",
]
)

for participant in (
Participant.objects.select_related("seat")
.select_related("seat__table")
Expand All @@ -1633,6 +1640,7 @@ def export_participants(request, year, banquet_pk):
participant.seat,
", ".join(str(x) for x in participant.dietary_restrictions.all()),
participant.other_dietary_restrictions,
participant.dietary_preference,
"https://ais.armada.nu/banquet/" + participant.token,
participant.ticket_scanned,
]
Expand Down
30 changes: 30 additions & 0 deletions templates/banquet/email/invitation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "email/base.html" %}

{% block content %}
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
Hello {{ name }}!
</p>
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
You have been invited to the Grand Banquet of THS Armada.
</p>
{% include 'email/button.html' with content="Go to invitation" url=link %}
{% include 'email/divider.html' %}
<ul>
<li style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
Time: {{ date|date:"Y-m-d" }} {{ date|date:"H:i" }}.
</li>
<li style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
Location: {{ location }}.
</li>
<li style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
Please note that this is an automatic email, and you cannot respond to this email.
You can always reach out to {% include 'email/link.html' with url='mailto:[email protected]' text='[email protected]' %} if you have any questions.
</li>
</ul>
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
See you at the banquet!
</p>
<p style="font-size:16px;line-height:24px;margin:16px 0;color:#525f7f;text-align:left">
The Banquet Team of THS Armada {{ year }}
</p>
{% endblock %}
20 changes: 15 additions & 5 deletions templates/banquet/manage_participant.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ <h1>{{ banquet.name }} – Participant</h1>
</p>

<h2>Ticket link</h2>
{% if banquet.background %}
<p>Give the following link to the participant.</p>

<input type="text" value="https://ais.armada.nu{% url 'banquet_participant_display' participant.token %}" />

{% if invitation %}
{% if invitation.user is None %}
<p>Give the following link to the participant.</p>
<input type="text" value="https://ais.armada.nu{% url 'banquet_participant_display' participant.token %}" />
{% else %}
<p>This invitation is tied to a user account. Ask {{ invitation.user.get_full_name }} to sign in to the AIS and click Banquet in the menu.</p>
{% endif %}

{% if invitation.has_sent_mail %}
<a href="{% url 'banquet_send_invitation_button' fair.year banquet.pk invitation.pk %}" class="btn btn-default" onclick="return confirm('An invite mail has already been sent to this person. Send again?')">Send invitation mail (already sent)</a>
{% else %}
<a href="{% url 'banquet_send_invitation_button' fair.year banquet.pk invitation.pk %}" class="btn btn-default">Send invitation mail</a>
{% endif %}
{% else %}
<p>Before the generated links can work, a background image needs to be uploaded (ask an IT admin) for the banquet.</p>
<p class="text-danger">The participant has no invitation.</p>
{% endif %}
{% endblock %}
8 changes: 7 additions & 1 deletion templates/banquet/participant_display.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
</head>

<body>
{% if not participant.banquet.background %}
<h1><span style="color: red;">Warning:</span> background image not uploaded!</h1>
{% endif %}

<div class="container" style="max-width: 900px;">
<style type="text/css">
#map
{
background-image: url('{{ participant.banquet.background.url }}');
{% if participant.banquet.background %}
background-image: url('{{ participant.banquet.background.url }}');
{% endif %}
background-size: cover;
width: 100%;
height: 300px;
Expand Down
1 change: 1 addition & 0 deletions util/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ def send_mail(
email.send()
except Exception as e:
print("Failed to send email: ", e)
raise e

0 comments on commit 28a1fbe

Please sign in to comment.