mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 20:48:25 -04:00
Refactor content preview method into generator
This will let us break up this method a bit more, rather than make the dictionary comprehension even more involved and nested. Means we need to `list()` it, because generator expressions cast to boolean are `True`, even if they’re empty – Python doesn’t evaluate them. ie: ```python bool(list()) >>> False ``` ```python bool((item for item in list())) >>> True ``` ```python bool(list(item for item in list())) >>> False ```
This commit is contained in:
@@ -261,7 +261,9 @@ def get_notifications(service_id, message_type, status_override=None):
|
|||||||
),
|
),
|
||||||
'notifications': render_template(
|
'notifications': render_template(
|
||||||
'views/activity/notifications.html',
|
'views/activity/notifications.html',
|
||||||
notifications=add_preview_of_content_to_notifications(notifications['notifications']),
|
notifications=list(add_preview_of_content_to_notifications(
|
||||||
|
notifications['notifications']
|
||||||
|
)),
|
||||||
page=page,
|
page=page,
|
||||||
prev_page=prev_page,
|
prev_page=prev_page,
|
||||||
next_page=next_page,
|
next_page=next_page,
|
||||||
@@ -388,8 +390,8 @@ def get_job_partials(job):
|
|||||||
|
|
||||||
|
|
||||||
def add_preview_of_content_to_notifications(notifications):
|
def add_preview_of_content_to_notifications(notifications):
|
||||||
return [
|
for notification in notifications:
|
||||||
dict(
|
yield dict(
|
||||||
preview_of_content=(
|
preview_of_content=(
|
||||||
str(Template(notification['template'], notification['personalisation']))
|
str(Template(notification['template'], notification['personalisation']))
|
||||||
if notification['template']['template_type'] == 'sms' else
|
if notification['template']['template_type'] == 'sms' else
|
||||||
@@ -397,5 +399,3 @@ def add_preview_of_content_to_notifications(notifications):
|
|||||||
),
|
),
|
||||||
**notification
|
**notification
|
||||||
)
|
)
|
||||||
for notification in notifications
|
|
||||||
]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user