From 1f2f75a7f1c2fc6a8296fbfaa69896344619ea77 Mon Sep 17 00:00:00 2001 From: Didrik Munther Date: Wed, 2 Oct 2024 13:41:55 +0200 Subject: [PATCH] Add last minute banquet changes --- banquet/forms.py | 7 +++++++ banquet/functions.py | 12 ++++++------ banquet/views.py | 16 +++++++++++++++- people/migrations/0016_add_show_in_banquet.py | 18 ++++++++++++++++++ people/models.py | 1 + templates/banquet/email/invitation.html | 7 +++++-- templates/banquet/invitation_internal.html | 2 +- templates/banquet/manage_participants.html | 8 +++++--- 8 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 people/migrations/0016_add_show_in_banquet.py diff --git a/banquet/forms.py b/banquet/forms.py index 20a3fc409..ce8b91be4 100644 --- a/banquet/forms.py +++ b/banquet/forms.py @@ -14,6 +14,8 @@ import re import csv +from people.models import DietaryRestriction + from .models import ( DietaryPreference, Participant, @@ -66,6 +68,11 @@ def __init__(self, *args, **kwargs): banquet ) + self.fields["dietary_restrictions"].queryset = self.get_dietary_restrictions() + + def get_dietary_restrictions(self): + return DietaryRestriction.objects.filter(show_in_banquet=True) + def get_dietary_preferences(self, banquet): # Custom function to retrieve dietary preferences for the given banquet return DietaryPreference.objects.filter(banquet=banquet) diff --git a/banquet/functions.py b/banquet/functions.py index b52afd4e7..2fa3e2385 100644 --- a/banquet/functions.py +++ b/banquet/functions.py @@ -3,7 +3,7 @@ from util.email import send_mail -def send_invitation_mail(request, invitation, name, date, location, link, email, fair): +def send_invitation_mail(request, invitation, name, banquet, link, email, fair): """Send banquet invitation mail""" try: send_mail( @@ -11,12 +11,13 @@ def send_invitation_mail(request, invitation, name, date, location, link, email, template="banquet/email/invitation.html", context={ "name": name, - "date": date, - "location": location, + "date": banquet.date, + "location": banquet.location, + "dress_code": banquet.dress_code, "link": link, "year": fair.year, }, - subject="Initial registration received!", + subject="THS Armada Banquet Invitation", to=[email], # file_paths=[settings.MEDIA_ROOT + signature.contract.contract.url[6:]], ) @@ -64,8 +65,7 @@ def send_confirmation_email(request, invitation, name, email_address, fair): request, invitation, name, - banquet.date, - banquet.location, + banquet, link, email_address, fair, diff --git a/banquet/views.py b/banquet/views.py index 2e9728c3b..cfa8c14a0 100644 --- a/banquet/views.py +++ b/banquet/views.py @@ -960,6 +960,13 @@ def manage_participant(request, year, banquet_pk, participant_pk): ) +def get_dietary_string(participant): + dietary_restrictions = participant.dietary_restrictions + if dietary_restrictions.count() == 0: + return participant.dietary_preference + return f"{participant.dietary_preference} ({', '.join(dietary_restrictions.values_list('name', flat=True))})" + + @permission_required("banquet.base") def manage_participants(request, year, banquet_pk): fair = get_object_or_404(Fair, year=year) @@ -980,6 +987,7 @@ def manage_participants(request, year, banquet_pk): if participant.user else participant.email_address ), + "dietary": get_dietary_string(participant), "alcohol": participant.alcohol, "seat": participant.seat, "invitation": participant.invitation_set.first(), @@ -1232,7 +1240,13 @@ def send_invitation_button(request, year, banquet_pk, invitation_pk): ) send_invitation_mail( - request, invitation, name, banquet.date, banquet.location, link, email, fair + request, + invitation, + name, + banquet, + link, + email, + fair, ) return render( diff --git a/people/migrations/0016_add_show_in_banquet.py b/people/migrations/0016_add_show_in_banquet.py new file mode 100644 index 000000000..87d940847 --- /dev/null +++ b/people/migrations/0016_add_show_in_banquet.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.24 on 2024-10-02 13:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0015_remove_dietary_preferences'), + ] + + operations = [ + migrations.AddField( + model_name='dietaryrestriction', + name='show_in_banquet', + field=models.BooleanField(default=True), + ), + ] diff --git a/people/models.py b/people/models.py index ee0580aa1..59071a04b 100644 --- a/people/models.py +++ b/people/models.py @@ -29,6 +29,7 @@ def __str__(self): class DietaryRestriction(models.Model): name = models.CharField(max_length=255) + show_in_banquet = models.BooleanField(default=True) class Meta: ordering = ["name"] diff --git a/templates/banquet/email/invitation.html b/templates/banquet/email/invitation.html index 11cd93329..e1404e2a0 100644 --- a/templates/banquet/email/invitation.html +++ b/templates/banquet/email/invitation.html @@ -17,10 +17,13 @@ Location: {{ location }}.
  • - 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:support@armada.nu' text='support@armada.nu' %} if you have any questions. + Dress code: {{ dress_code }}.
  • +

    + 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:support@armada.nu' text='support@armada.nu' %} if you have any questions. +

    See you at the banquet!

    diff --git a/templates/banquet/invitation_internal.html b/templates/banquet/invitation_internal.html index 28dce2cb7..36cc9cc51 100644 --- a/templates/banquet/invitation_internal.html +++ b/templates/banquet/invitation_internal.html @@ -160,7 +160,7 @@

    Thank you!

  • Dietary restrictions: - {% if invitation.participant.dietary_restrictions.all %} + {% if invitation.participant.dietary_restrictions %} {{ invitation.participant.dietary_restrictions.all | join:', ' }} {% else %} none diff --git a/templates/banquet/manage_participants.html b/templates/banquet/manage_participants.html index 3dd070367..82ae9531f 100644 --- a/templates/banquet/manage_participants.html +++ b/templates/banquet/manage_participants.html @@ -22,8 +22,9 @@

    {{ banquet.name }} – Participants ({{ participants | length }})

    Name E-mail address Alcohol? - Seat - Options + Preference (Restrictions) + + Options @@ -43,7 +44,8 @@

    {{ banquet.name }} – Participants ({{ participants | length }})

    {{ participant.email_address }} {% if participant.alcohol %} Yes {% else %} No {% endif %} - {% if participant.seat %} {{ participant.seat.table.name }} – {{ participant.seat.name }} {% endif %} + {{ participant.dietary }} + Details {% endfor %}