Skip to content

Commit

Permalink
feat: Add banquet dietary preferences (#1265)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes: #
  • Loading branch information
didrikmunther authored Sep 20, 2024
1 parent 1433048 commit c72ee44
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 3 deletions.
6 changes: 6 additions & 0 deletions banquet/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin
from .models import (
Banquet,
DietaryPreference,
Participant,
InvitationGroup,
Invitation,
Expand Down Expand Up @@ -59,3 +60,8 @@ class AfterPartyInvitationAdmin(ModelAdminImproved):
class AfterPartyTicketAdmin(ModelAdminImproved):
list_filter = ["banquet", "has_paid"]
list_display = ["name", "email_address", "has_paid"]


@admin.register(DietaryPreference)
class DietaryPreferenceAdmin(ModelAdminImproved):
pass
21 changes: 21 additions & 0 deletions banquet/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import csv

from .models import (
DietaryPreference,
Participant,
InvitationGroup,
Invitation,
Expand Down Expand Up @@ -51,6 +52,24 @@ def fix_phone_number(n):


class ParticipantForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

participant = kwargs.pop("instance", None)
banquet = participant.banquet

# Set empty_label to None to remove the default "------"
self.fields["dietary_preference"].empty_label = None

if banquet:
self.fields["dietary_preference"].queryset = self.get_dietary_preferences(
banquet
)

def get_dietary_preferences(self, banquet):
# Custom function to retrieve dietary preferences for the given banquet
return DietaryPreference.objects.filter(banquet=banquet)

def clean(self):
super(ParticipantForm, self).clean()

Expand Down Expand Up @@ -83,6 +102,7 @@ class Meta:
"name",
"email_address",
"phone_number",
"dietary_preference",
"dietary_restrictions",
"other_dietary_restrictions",
"alcohol",
Expand All @@ -91,6 +111,7 @@ class Meta:
widgets = {
"name": forms.TextInput(attrs={"readonly": "readonly"}),
"email_address": forms.TextInput(attrs={"readonly": "readonly"}),
"dietary_preference": forms.RadioSelect(),
"dietary_restrictions": forms.CheckboxSelectMultiple(),
"other_dietary_restrictions": forms.TextInput(),
"alcohol": forms.RadioSelect(),
Expand Down
25 changes: 25 additions & 0 deletions banquet/migrations/0048_add_dietary_preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.2.24 on 2024-09-10 11:08

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("people", "0014_add_dietary_preferences"),
("banquet", "0047_has_sent_mail"),
]

operations = [
migrations.AddField(
model_name="participant",
name="dietary_preference",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="people.DietaryPreference",
),
),
]
50 changes: 50 additions & 0 deletions banquet/migrations/0049_change_dietary_preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by Django 2.2.24 on 2024-09-10 11:14

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("banquet", "0048_add_dietary_preferences"),
]

operations = [
migrations.CreateModel(
name="DietaryPreference",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("order", models.IntegerField(default=0)),
(
"banquet",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="banquet.Banquet",
),
),
],
options={
"ordering": ["order", "name"],
},
),
migrations.AlterField(
model_name="participant",
name="dietary_preference",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="banquet.DietaryPreference",
),
),
]
23 changes: 23 additions & 0 deletions banquet/migrations/0050_change_dietary_preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.24 on 2024-09-10 11:20

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("banquet", "0049_change_dietary_preferences"),
]

operations = [
migrations.AlterField(
model_name="participant",
name="dietary_preference",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="banquet.DietaryPreference",
),
),
]
15 changes: 15 additions & 0 deletions banquet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ class Meta:
ordering = ["year"]


class DietaryPreference(models.Model):
name = models.CharField(max_length=255)
order = models.IntegerField(default=0)
banquet = models.ForeignKey(Banquet, on_delete=models.CASCADE)

class Meta:
ordering = ["order", "name"]

def __str__(self):
return self.name


class Participant(models.Model):
token = models.CharField(
max_length=32, unique=True, default=get_random_32_length_string
Expand All @@ -148,6 +160,9 @@ class Participant(models.Model):
max_length=75, blank=True, null=True
) # None if a user is provided, required for others
dietary_restrictions = models.ManyToManyField(DietaryRestriction, blank=True)
dietary_preference = models.ForeignKey(
DietaryPreference, null=True, on_delete=models.CASCADE
)
other_dietary_restrictions = models.CharField(max_length=75, blank=True, null=True)
alcohol = models.BooleanField(choices=[(True, "Yes"), (False, "No")], default=True)
seat = models.OneToOneField(Seat, blank=True, null=True, on_delete=models.CASCADE)
Expand Down
1 change: 1 addition & 0 deletions banquet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ def send_invitation_button(request, year, banquet_pk, invitation_pk):
"email": email,
},
)

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

return render(
Expand Down
3 changes: 0 additions & 3 deletions people/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from django.contrib import admin
from .models import Language, Programme, Profile, DietaryRestriction
from improved_admin import ModelAdminImproved
Expand Down
37 changes: 37 additions & 0 deletions people/migrations/0014_add_dietary_preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 2.2.24 on 2024-09-10 11:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("people", "0013_add_armada_email"),
]

operations = [
migrations.CreateModel(
name="DietaryPreference",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=255)),
("order", models.IntegerField(default=0)),
],
options={
"ordering": ["order", "name"],
},
),
migrations.AlterField(
model_name="profile",
name="no_dietary_restrictions",
field=models.BooleanField(default=False),
),
]
16 changes: 16 additions & 0 deletions people/migrations/0015_remove_dietary_preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 2.2.24 on 2024-09-10 11:14

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("people", "0014_add_dietary_preferences"),
]

operations = [
migrations.DeleteModel(
name="DietaryPreference",
),
]

0 comments on commit c72ee44

Please sign in to comment.