mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 21:48:49 -04:00
Merge pull request #3016 from alphagov/use-utils-to-format-broadcast-content
Use utils template to format broadcast content
This commit is contained in:
@@ -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 don’t 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
|
||||
|
||||
@@ -2342,7 +2342,31 @@ class BroadcastEvent(db.Model):
|
||||
|
||||
@property
|
||||
def reference(self):
|
||||
return BroadcastMessageTemplate.from_event(self.serialize()).reference
|
||||
notify_email_domain = current_app.config['NOTIFY_EMAIL_DOMAIN']
|
||||
return (
|
||||
f'https://www.{notify_email_domain}/,'
|
||||
f'{self.id},'
|
||||
f'{self.sent_at_as_cap_datetime_string}'
|
||||
)
|
||||
|
||||
@property
|
||||
def sent_at_as_cap_datetime_string(self):
|
||||
return self.formatted_datetime_for('sent_at')
|
||||
|
||||
def formatted_datetime_for(self, property_name):
|
||||
return self.convert_naive_utc_datetime_to_cap_standard_string(
|
||||
getattr(self, property_name)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def convert_naive_utc_datetime_to_cap_standard_string(dt):
|
||||
"""
|
||||
As defined in section 3.3.2 of
|
||||
http://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2-os.html
|
||||
They define the standard "YYYY-MM-DDThh:mm:ssXzh:zm", where X is
|
||||
`+` if the timezone is > UTC, otherwise `-`
|
||||
"""
|
||||
return f"{dt.strftime('%Y-%m-%dT%H:%M:%S')}-00:00"
|
||||
|
||||
def get_earlier_message_references(self):
|
||||
from app.dao.broadcast_message_dao import get_earlier_events_for_broadcast_event
|
||||
|
||||
Reference in New Issue
Block a user