Skip to content

Commit

Permalink
Convert grant waiting list templates (#4081)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoacierno authored Sep 29, 2024
1 parent 639422d commit 5bf3fa1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
20 changes: 11 additions & 9 deletions backend/grants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ def send_grant_reply_approved_email(*, grant_id, is_reminder):
def send_grant_reply_waiting_list_email(*, grant_id):
logger.info("Sending Reply WAITING LIST email for Grant %s", grant_id)

_send_grant_waiting_list_email(grant_id, template=EmailTemplate.GRANT_WAITING_LIST)
_send_grant_waiting_list_email(
grant_id, template_identifier=EmailTemplateIdentifier.grant_waiting_list
)


@app.task
def send_grant_reply_waiting_list_update_email(*, grant_id):
logger.info("Sending Reply WAITING LIST UPDATE email for Grant %s", grant_id)

_send_grant_waiting_list_email(
grant_id, template=EmailTemplate.GRANT_WAITING_LIST_UPDATE
grant_id, template_identifier=EmailTemplateIdentifier.grant_waiting_list_update
)


Expand Down Expand Up @@ -158,21 +160,21 @@ def send_grant_voucher_email(*, grant_id):
grant.save()


def _send_grant_waiting_list_email(grant_id, template):
def _send_grant_waiting_list_email(grant_id, template_identifier):
grant = Grant.objects.get(id=grant_id)
reply_url = urljoin(settings.FRONTEND_URL, "/grants/reply/")

subject = "Financial Aid Update"
deadline = grant.conference.deadlines.filter(
type="custom", name__contains={"en": "Update Grants in Waiting List"}
).first()

_send_grant_email(
template=template,
subject=subject,
_new_send_grant_email(
template_identifier=template_identifier,
grant=grant,
replyLink=reply_url,
grantsUpdateDeadline=f"{deadline.start:%-d %B %Y}",
placeholders={
"reply_url": reply_url,
"grants_update_deadline": f"{deadline.start:%-d %B %Y}",
},
)

logger.info("Email sent for Grant %s", grant.id)
Expand Down
38 changes: 16 additions & 22 deletions backend/grants/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,17 @@ def test_send_grant_reply_waiting_list_email(settings):
)
grant = GrantFactory(conference=conference, user=user)

with patch("grants.tasks.send_email") as email_mock:
with patch("grants.tasks.EmailTemplate") as mock_email_template:
send_grant_reply_waiting_list_email(grant_id=grant.id)

email_mock.assert_called_once_with(
template=EmailTemplate.GRANT_WAITING_LIST,
to="marco@placeholder.it",
subject=f"[{grant.conference.name}] Financial Aid Update",
variables={
"firstname": "Marco Acierno",
"conferenceName": grant.conference.name.localize("en"),
"replyLink": "https://pycon.it/grants/reply/",
"grantsUpdateDeadline": "1 March 2023",
mock_email_template.objects.for_conference().get_by_identifier().send_email.assert_called_once_with(
recipient=user,
placeholders={
"user_name": "Marco Acierno",
"conference_name": grant.conference.name.localize("en"),
"grants_update_deadline": "1 March 2023",
"reply_url": "https://pycon.it/grants/reply/",
},
reply_to=["grants@pycon.it"],
)


Expand Down Expand Up @@ -334,20 +331,17 @@ def test_send_grant_reply_waiting_list_update_email(settings):
)
conference_name = grant.conference.name.localize("en")

with patch("grants.tasks.send_email") as email_mock:
with patch("grants.tasks.EmailTemplate") as mock_email_template:
send_grant_reply_waiting_list_update_email(
grant_id=grant.id,
)

email_mock.assert_called_once_with(
template=EmailTemplate.GRANT_WAITING_LIST_UPDATE,
to="marco@placeholder.it",
variables={
"firstname": "Marco Acierno",
"conferenceName": conference_name,
"grantsUpdateDeadline": "1 March 2023",
"replyLink": "https://pycon.it/grants/reply/",
mock_email_template.objects.for_conference().get_by_identifier().send_email.assert_called_once_with(
recipient=user,
placeholders={
"user_name": "Marco Acierno",
"conference_name": conference_name,
"grants_update_deadline": "1 March 2023",
"reply_url": "https://pycon.it/grants/reply/",
},
reply_to=["grants@pycon.it"],
subject=f"[{conference_name}] Financial Aid Update",
)
14 changes: 14 additions & 0 deletions backend/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ class EmailTemplate(TimeStampedModel):
"conference_name",
"user_name",
],
EmailTemplateIdentifier.grant_waiting_list: [
*BASE_PLACEHOLDERS,
"conference_name",
"user_name",
"reply_url",
"grants_update_deadline",
],
EmailTemplateIdentifier.grant_waiting_list_update: [
*BASE_PLACEHOLDERS,
"conference_name",
"user_name",
"reply_url",
"grants_update_deadline",
],
}

conference = models.ForeignKey(
Expand Down
2 changes: 0 additions & 2 deletions backend/notifications/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

class EmailTemplate(str, Enum):
# Grants
GRANT_WAITING_LIST = "grants-waiting-list"
GRANT_WAITING_LIST_UPDATE = "grants-waiting-list-update"
GRANT_VOUCHER_CODE = "grants-voucher-code"

# Users
Expand Down

0 comments on commit 5bf3fa1

Please sign in to comment.