Skip to content

Commit

Permalink
Merge pull request #2658 from carpentries/chore/Add-missing-context-v…
Browse files Browse the repository at this point in the history
…ariables

[Emails] Add missing context variables
  • Loading branch information
pbanaszkiewicz authored Jun 11, 2024
2 parents c05b45b + 561e399 commit d143fe7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion amy/emails/actions/new_self_organised_workshop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
import logging
from typing import Unpack

Expand Down Expand Up @@ -66,7 +66,10 @@ def get_context(
"assignee": self_organised_submission.assigned_to
or event.assigned_to
or None,
"workshop_host": event.host,
"event": event,
"short_notice": bool(event.start)
and event.start <= (timezone.now().date() + timedelta(days=10)),
"self_organised_submission": self_organised_submission,
}

Expand All @@ -80,7 +83,11 @@ def get_context_json(
if context["assignee"]
else scalar_value_none()
),
"workshop_host": api_model_url(
"organization", context["workshop_host"].pk
),
"event": api_model_url("event", context["event"].pk),
"short_notice": scalar_value_url("bool", str(context["short_notice"])),
"self_organised_submission": api_model_url(
"selforganisedsubmission", context["self_organised_submission"].pk
),
Expand Down
7 changes: 6 additions & 1 deletion amy/emails/tests/actions/test_new_self_organised_workshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from emails.models import EmailTemplate, ScheduledEmail
from emails.schemas import ContextModel, ToHeaderModel
from emails.signals import new_self_organised_workshop_signal
from emails.utils import api_model_url, scalar_value_none
from emails.utils import api_model_url, scalar_value_none, scalar_value_url
from extrequests.models import SelfOrganisedSubmission
from workshops.models import Event, Language, Organization, Tag
from workshops.tests.base import TestBase
Expand Down Expand Up @@ -203,7 +203,12 @@ def test_email_scheduled(
context_json=ContextModel(
{
"assignee": scalar_value_none(),
"workshop_host": api_model_url(
"organization",
organization.pk, # type: ignore
),
"event": api_model_url("event", event.pk),
"short_notice": scalar_value_url("bool", "False"),
"self_organised_submission": api_model_url(
"selforganisedsubmission", submission.pk
),
Expand Down
2 changes: 2 additions & 0 deletions amy/emails/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class NewSelfOrganisedWorkshopContext(TypedDict):
event: Event
self_organised_submission: SelfOrganisedSubmission
assignee: Person | None
workshop_host: Organization
short_notice: bool


class NewSelfOrganisedWorkshopKwargs(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion amy/scripts/seed_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
reply_to_header="",
cc_header=[],
bcc_header=[],
subject="Time to Recruit Helpers for workshop at {{ workshop.venue }}",
subject="Time to Recruit Helpers for workshop at {{ event.venue }}",
body=(
"Hey everyone, please remember to seek helpers for the workshop "
"{{ event.slug }} -Best, {{ assignee.full_name }}."
Expand Down
2 changes: 1 addition & 1 deletion amy/templates/emails/email_template_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{% endif %}
</td>
<td>{{ template.subject }}</td>
<td>{{ template.body }}</td>
<td>{{ template.body|truncatechars:150 }}</td>
</tr>
{% endfor %}
</table>
Expand Down

0 comments on commit d143fe7

Please sign in to comment.