Skip to content

Commit

Permalink
Add confirmation email functionality for bartender applications
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersSeverinsen committed Dec 12, 2024
1 parent 71e62e1 commit 19206df
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 119 deletions.
37 changes: 37 additions & 0 deletions bartenders/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,43 @@ def send_email(self, pk):
to=["[email protected]"],
)

def send_confirmation_email(self, pk):
d = self.cleaned_data

extra_info = ""
if d["info"]:
extra_info = f"""
Ekstra information:
{d["info"]}
"""
d["extra_info"] = extra_info

return send_template_email(
subject=f"Kvittering for bartendertilmelding til fredagscaféen",
body_template="""Dette er en automatisk email.
Hej {name},
Tak for din ansøgning om at blive bartender i fredagscaféen!
Vi gennemgår din ansøgning på næste bestyrelsesmøde, så forvent lidt ventetid, før du hører fra os.
Kopi af din ansøgning:
Navn: {name}
Brugernavn: {username}
Studienummer: {studentNumber}
Email: {email}
Telefonnummer: {phoneNumber}
{extra_info}
/snek""",
text_format={**d},
html_format={
**d,
},
to=[d["email"]],
)


class BartenderInfoForm(forms.ModelForm):
class Meta:
Expand Down
57 changes: 57 additions & 0 deletions bartenders/migrations/0005_auto_20241212_2345.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 3.2.4 on 2024-12-12 22:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
(
"bartenders",
"0004_alter_bartender_email_alter_bartender_tshirt_size_and_more",
),
]

operations = [
migrations.AlterModelOptions(
name="bartendershift",
options={"ordering": ("-start_datetime",)},
),
migrations.AlterField(
model_name="bartender",
name="email",
field=models.EmailField(
help_text="En post.au mail fungerer ikke",
max_length=254,
unique=True,
verbose_name="E-mail",
),
),
migrations.AlterField(
model_name="bartender",
name="studentNumber",
field=models.IntegerField(null=True, verbose_name="Studienummer"),
),
migrations.AlterField(
model_name="bartenderapplication",
name="email",
field=models.EmailField(
help_text="En post.au mail fungerer ikke",
max_length=254,
unique=True,
verbose_name="E-mail",
),
),
migrations.AlterField(
model_name="bartenderapplication",
name="info",
field=models.TextField(
help_text="Fortæl lidt om dig selv, og hvorfor du tror at lige præcist du, ville være en god bartender"
),
),
migrations.AlterField(
model_name="bartenderapplication",
name="studentNumber",
field=models.IntegerField(null=True, verbose_name="Studienummer"),
),
]
11 changes: 7 additions & 4 deletions bartenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class Meta:
)
email = models.EmailField(
unique=True,
blank=True,
blank=False,
verbose_name=_("E-mail"),
help_text=_("En post.au mail fungerer ikke"),
)
studentNumber = models.IntegerField(
blank=True, null=True, verbose_name=_("Studienummer")
blank=False, null=True, verbose_name=_("Studienummer")
)
phoneNumber = models.IntegerField(
blank=True, null=True, verbose_name=_("Telefonnummer")
Expand Down Expand Up @@ -242,7 +242,10 @@ class BartenderApplication(BartenderCommon):
study = models.CharField(max_length=50, verbose_name=_("Studie"))
study_year = models.IntegerField(verbose_name=_("Årgang"))
info = models.TextField(
blank=True, help_text=_("Eventuelle ekstra info til bestyrelsen skrives her")
blank=False,
help_text=_(
"Fortæl lidt om dig selv, og hvorfor du tror at lige præcist du, ville være en god bartender"
),
)

created = models.DateTimeField(auto_now_add=True)
Expand Down Expand Up @@ -400,7 +403,7 @@ class BartenderShift(models.Model):
)

class Meta:
ordering = ("start_datetime",)
ordering = ("-start_datetime",)

def save(self, *args, **kwargs):
if not self.end_datetime:
Expand Down
2 changes: 1 addition & 1 deletion bartenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_sending_application(self):
# Test that application was made
self.assertTrue(BartenderApplication.objects.exists())
# And mail was sent
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(len(mail.outbox), 2)

def test_invalid_application(self):
data = dict(
Expand Down
3 changes: 3 additions & 0 deletions bartenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def form_valid(self, form):

# Send email to best
form.send_email(self.object.pk)

# Send email to applicant
form.send_confirmation_email(self.object.pk)
messages.success(self.request, _("Din ansøgning er blevet indsendt."))

return response
Expand Down
2 changes: 1 addition & 1 deletion fredagscafeen/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def send_template_email(
html_format={},
from_email="[email protected]",
cc=[],
reply_to=[],
reply_to=["[email protected]"],
):
body_text = render_to_string(
"email.txt", {"content": body_template.format(**text_format)}
Expand Down
Binary file modified locale/da/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 19206df

Please sign in to comment.