Use utils template to format broadcast content

Brings in:
- [x] https://github.com/alphagov/notifications-utils/pull/801

Formats the content of the template at the time of creating the event.
This means that any downstream code (eg Celery tasks) can assume the
content is already formatted correctly.

Also, these downstream tasks don’t  know which template the broadcast
was created from, so if we support personalisation in the future this is
the most sensible place to bring together the template and the
personalisation.

---

I had to re-create some of the deleted code from utils for stuff like
formatting the timestamp to the CAP standard.
This commit is contained in:
Chris Hill-Scott
2020-10-26 17:39:11 +00:00
parent 55efbb0bb1
commit 28f01bd776
4 changed files with 37 additions and 11 deletions

View File

@@ -185,13 +185,16 @@ def _create_broadcast_event(broadcast_message):
else:
transmitted_finishes_at = broadcast_message.finishes_at
# TODO: This doesn't support placeholders yet. We shouldn't use BroadcastMessageTemplate when we add placeholders
# as that just outputs XML, we need the raw text.
template = broadcast_message.template._as_utils_template_with_personalisation(
# Broadcast events dont support personalisation yet
values={}
)
event = BroadcastEvent(
service=broadcast_message.service,
broadcast_message=broadcast_message,
message_type=msg_types[broadcast_message.status],
transmitted_content={"body": broadcast_message.template.content},
transmitted_content={"body": str(template)},
transmitted_areas=broadcast_message.areas,
# TODO: Probably move this somewhere more standalone too and imply that it shouldn't change. Should it include
# a service based identifier too? eg "flood-warnings@notifications.service.gov.uk" or similar