Skip to content

Commit

Permalink
forces nl locale on generic emails (closes #186)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed May 14, 2024
1 parent 2ff3fac commit 72ef8a5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
16 changes: 9 additions & 7 deletions lab/experiments/models/appointment_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from cdh.mail.classes import TemplateEmail
from django.db import models
from django.utils import translation
from django.utils.translation import gettext_lazy as _

from main.models import User
Expand Down Expand Up @@ -122,10 +123,11 @@ def _inform_leaders(appointment: Appointment) -> None:
def _send_cancel_confirmation(appointment: Appointment) -> None:
context = {"appointment": appointment}

mail = TemplateEmail(
html_template="mail/appointment/canceled.html",
context=context,
to=[appointment.participant.email],
subject=_("experiments:mail:appointment:canceled:subject")
)
mail.send()
with translation.override("nl"):
mail = TemplateEmail(
html_template="mail/appointment/canceled.html",
context=context,
to=[appointment.participant.email],
subject=_("experiments:mail:appointment:canceled:subject")
)
mail.send()
26 changes: 14 additions & 12 deletions lab/mailauth/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime, timedelta
from datetime import datetime
from secrets import token_urlsafe
from typing import List, Optional, Tuple

import cdh.core.fields as e_fields
from cdh.mail.classes import TemplateEmail
from django.conf import settings
from django.db import models
from django.utils import translation
from django.utils.translation import gettext_lazy as _

from participants.models import Participant
Expand All @@ -24,17 +25,18 @@ class MailAuth(models.Model):
participant = models.ForeignKey("participants.Participant", on_delete=models.CASCADE, null=True)

def send(self, addressee: str):
mail = TemplateEmail(
html_template="mailauth/link.html",
context=dict(
addressee=addressee, # parent name
base_url=settings.PARENT_URI,
link_token=self.link_token,
),
to=[self.email],
subject=_("mailauth:send:subject"),
)
mail.send()
with translation.override("nl"):
mail = TemplateEmail(
html_template="mailauth/link.html",
context=dict(
addressee=addressee, # parent name
base_url=settings.PARENT_URI,
link_token=self.link_token,
),
to=[self.email],
subject=_("mailauth:send:subject"),
)
mail.send()

def get_link(self, redirect=None):
return settings.PARENT_URI + f"auth/{self.link_token}?redirect={redirect}"
Expand Down
22 changes: 12 additions & 10 deletions lab/signups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cdh.mail.classes import TemplateEmail
from django.conf import settings
from django.db import models
from django.utils import translation
from django.utils.translation import gettext_lazy as _


Expand Down Expand Up @@ -59,13 +60,14 @@ class Status(models.TextChoices):
link_token = models.CharField(max_length=64, default=token_urlsafe, unique=True)

def send_email_validation(self):
mail = TemplateEmail(
html_template="signups/mail/validation.html",
context=dict(
base_url=settings.PARENT_URI,
link_token=self.link_token,
),
to=[self.email],
subject="please validate your email",
)
mail.send()
with translation.override("nl"):
mail = TemplateEmail(
html_template="signups/mail/validation.html",
context=dict(
base_url=settings.PARENT_URI,
link_token=self.link_token,
),
to=[self.email],
subject=_("signups:mail:validation:subject"),
)
mail.send()
16 changes: 9 additions & 7 deletions lab/survey_admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from cdh.mail.classes import TemplateEmail
from django.db import models
from django.utils import translation

from mailauth.models import create_mail_auth
from participants.models import Participant
Expand Down Expand Up @@ -31,13 +32,14 @@ def get_link(self):

def send(self):
context = dict(link=self.get_link())
mail = TemplateEmail(
html_template="survey_admin/mail/invite.html",
context=context,
to=[self.participant.email],
subject="invitation to fill survey",
)
mail.send()
with translation.override("nl"):
mail = TemplateEmail(
html_template="survey_admin/mail/invite.html",
context=context,
to=[self.participant.email],
subject="invitation to fill survey",
)
mail.send()


class SurveyResponse(models.Model):
Expand Down

0 comments on commit 72ef8a5

Please sign in to comment.