From c4478204090f8dcf96e5f1d80907835e750ffe2f Mon Sep 17 00:00:00 2001
From: Ketan <73937490+devketanpro@users.noreply.github.com>
Date: Wed, 15 Jan 2025 15:44:38 +0530
Subject: [PATCH] STT-54: Update download, topic notification, and sharing
templates to display related event details (#1224)
* update download tempalates and add helper function in utils
* update agenda Print template
* update email templates
* update copy templates
* minor changes
* fix syntax
---
newsroom/agenda/utils.py | 13 +++++++++++++
newsroom/agenda/views.py | 4 +++-
newsroom/email.py | 6 +++++-
newsroom/templates/agenda_item_print.html | 20 ++++++++++++++++++++
newsroom/templates/copy_agenda_item.txt | 18 +++++++++++++++++-
newsroom/templates/download_agenda.txt | 18 +++++++++++++++++-
newsroom/templates/email_agenda.html | 20 ++++++++++++++++++++
newsroom/templates/email_agenda.txt | 16 +++++++++++++++-
newsroom/wire/formatters/text.py | 7 ++++++-
newsroom/wire/views.py | 2 ++
10 files changed, 118 insertions(+), 6 deletions(-)
diff --git a/newsroom/agenda/utils.py b/newsroom/agenda/utils.py
index 055b39658..a185ed216 100644
--- a/newsroom/agenda/utils.py
+++ b/newsroom/agenda/utils.py
@@ -307,3 +307,16 @@ def get_filtered_subject(
if not schemas:
return subject
return [subj for subj in subject if subj.get("scheme") in schemas]
+
+
+async def get_related_events(item: Dict[str, Any]) -> List[Dict[str, Any]]:
+ """
+ Get related events for an agenda item
+ param item: Agenda item
+ """
+ from .agenda_search import AgendaSearchServiceAsync # noqa
+
+ related_events = []
+ if item.get("event_ids"):
+ related_events = await AgendaSearchServiceAsync().get_items_for_action(item["event_ids"])
+ return related_events
diff --git a/newsroom/agenda/views.py b/newsroom/agenda/views.py
index 2c4b2ce7d..da88d4d1c 100644
--- a/newsroom/agenda/views.py
+++ b/newsroom/agenda/views.py
@@ -46,7 +46,7 @@
from .email import send_coverage_request_email
from .featured_service import FeaturedService
-from .utils import remove_fields_for_public_user, remove_restricted_coverage_info
+from .utils import remove_fields_for_public_user, remove_restricted_coverage_info, get_related_events
from .module import agenda_endpoints
from .agenda_service import AgendaItemService
from .agenda_search import AgendaSearchServiceAsync
@@ -112,6 +112,7 @@ async def item(args: AgendaItemViewArgs, params: AgendaItemParams, request: Requ
if params.print:
template = "agenda_item_print.html"
+ related_events = await get_related_events(agenda_item_dict)
await update_action_list([args.item_id], "prints", force_insert=True)
await HistoryService().create_history_record([agenda_item_dict], "print", user.id, user.company, params.type)
return await render_template(
@@ -123,6 +124,7 @@ async def item(args: AgendaItemViewArgs, params: AgendaItemParams, request: Requ
contacts=get_public_contacts(agenda_item_dict),
links=get_links(agenda_item_dict),
is_admin=user.is_admin_or_internal(),
+ related_events=related_events,
)
data = await get_view_data()
diff --git a/newsroom/email.py b/newsroom/email.py
index 9d5d7d1b7..85c5421b0 100644
--- a/newsroom/email.py
+++ b/newsroom/email.py
@@ -440,8 +440,11 @@ def _remove_restricted_coverage_info(item):
# TODO-ASYNC: change this to use newsroom.users.model.UserResourceModel only
async def _send_new_agenda_notification_email(user: User | UserResourceModel, topic_name: str, item: dict[str, Any]):
- user_dict: User = user.to_dict() if isinstance(user, ResourceModel) else user
+ # Import here to prevent circular imports
+ from newsroom.agenda.utils import get_related_events
+ user_dict: User = user.to_dict() if isinstance(user, ResourceModel) else user
+ related_events = await get_related_events(item)
_remove_restricted_coverage_info(item)
url = url_for_agenda(item, _external=True)
template_kwargs = dict(
@@ -458,6 +461,7 @@ async def _send_new_agenda_notification_email(user: User | UserResourceModel, to
links=get_links(item),
is_admin=is_admin_or_internal(user),
section="agenda",
+ related_events=related_events,
)
await send_user_email(
user=user,
diff --git a/newsroom/templates/agenda_item_print.html b/newsroom/templates/agenda_item_print.html
index 8c47cd620..86e641f21 100644
--- a/newsroom/templates/agenda_item_print.html
+++ b/newsroom/templates/agenda_item_print.html
@@ -69,5 +69,25 @@
{{ gettext('Coverages:') }}
{% endif %}
{% endfor %}
+ {%- if related_events %}
+ Related Events:
+ {%- for event in related_events %}
+
+ {%- if event.name %}
+
{{ event.name }}
+ {%- endif %}
+ {%- if event.slugline %}
+
Slugline: {{ event.slugline }}
+ {%- endif %}
+ {%- if event.headline %}
+
Headline: {{ event.headline }}
+ {%- endif %}
+ {%- if event.definition_long %}
+
Definition: {{ event.definition_long }}
+ {%- endif %}
+
{{ event | format_event_datetime }}
+
+ {%- endfor %}
+{%- endif %}
{% endblock %}
diff --git a/newsroom/templates/copy_agenda_item.txt b/newsroom/templates/copy_agenda_item.txt
index 8548be7b9..0fca8fbbe 100644
--- a/newsroom/templates/copy_agenda_item.txt
+++ b/newsroom/templates/copy_agenda_item.txt
@@ -49,4 +49,20 @@ Description: {{ plan.description_text | plain_text }}
{% endif -%}
{%- endfor -%}
{%- endfor -%}
-{%- endif -%}
\ No newline at end of file
+{%- endif -%}
+
+{%- if related_events %}
+Related_Events:
+{%- for event in related_events %}
+
+{% if event.name %}{{ event.name }}
+{% endif %}
+{%- if event.slugline %}Slugline: {{ event.slugline }}
+{% endif %}
+{%- if event.headline %}Headline: {{ event.headline }}
+{% endif %}
+{%- if event.definition_long %}Definition: {{ event.definition_long }}
+{% endif -%}
+{{ event | format_event_datetime }}
+{%- endfor %}
+{% endif %}
\ No newline at end of file
diff --git a/newsroom/templates/download_agenda.txt b/newsroom/templates/download_agenda.txt
index e312f3ef9..f1a8d44e7 100644
--- a/newsroom/templates/download_agenda.txt
+++ b/newsroom/templates/download_agenda.txt
@@ -23,4 +23,20 @@
{% if coverage.workflow_status %} Workflow Status: {{ coverage.workflow_status }}
{% endif -%}
Coverage Status: {{ coverage.coverage_status }}
-{%- endfor %}{% endif %}
\ No newline at end of file
+{%- endfor %}{% endif %}
+
+{%- if related_events %}
+Related_Events:
+{%- for event in related_events %}
+
+{% if event.name %}{{ event.name }}
+{% endif %}
+{%- if event.slugline %}Slugline: {{ event.slugline }}
+{% endif %}
+{%- if event.headline %}Headline: {{ event.headline }}
+{% endif %}
+{%- if event.definition_long %}Definition: {{ event.definition_long }}
+{% endif -%}
+{{ event | format_event_datetime }}
+{%- endfor %}
+{% endif %}
diff --git a/newsroom/templates/email_agenda.html b/newsroom/templates/email_agenda.html
index dbbaa4299..18c77881c 100644
--- a/newsroom/templates/email_agenda.html
+++ b/newsroom/templates/email_agenda.html
@@ -68,3 +68,23 @@ Planning item:
{% endif %}
{% endfor %}
+
+{% if related_events %}
+ Related Events:
+ {% for event in related_events %}
+
+ {% if event.name %}
+
{{ event.name }}
+ {% endif %}
+ {% if event.slugline %}
+
Slugline: {{ event.slugline }}
+ {% endif %}
+ {% if event.headline %}
+
Headline: {{ event.headline }}
+ {% endif %}
+ {% if event.definition_long %}
+
{{ event.definition_long }}
+ {% endif %}
+
+ {% endfor %}
+{% endif %}
diff --git a/newsroom/templates/email_agenda.txt b/newsroom/templates/email_agenda.txt
index 2b7d8eafa..cc5714e1a 100644
--- a/newsroom/templates/email_agenda.txt
+++ b/newsroom/templates/email_agenda.txt
@@ -23,4 +23,18 @@ Coverages:
Note: {{ cov['planning']['ednote'] }} {% endif %}{% if is_admin and cov.get('planning', {}).get('internal_note') %}Internal Note: {{ cov['planning']['internal_note'] }}{% endif %}
{% endfor %}
{% endif %}
-{% endfor %}
\ No newline at end of file
+{% endfor %}
+{%- if related_events %}
+Related_Events:
+{%- for event in related_events %}
+{% if event.name %}{{ event.name }}
+{% endif %}
+{%- if event.slugline %}Slugline: {{ event.slugline }}
+{% endif %}
+{%- if event.headline %}Headline: {{ event.headline }}
+{% endif %}
+{%- if event.definition_long %}Definition: {{ event.definition_long }}
+{% endif -%}
+{{ event | format_event_datetime }}
+{%- endfor %}
+{% endif %}
\ No newline at end of file
diff --git a/newsroom/wire/formatters/text.py b/newsroom/wire/formatters/text.py
index 14e6f7902..6981c5ade 100644
--- a/newsroom/wire/formatters/text.py
+++ b/newsroom/wire/formatters/text.py
@@ -18,7 +18,12 @@ class TextFormatter(BaseFormatter):
MIMETYPE = "text/plain"
async def format_item(self, item: dict[str, Any], item_type: str | None = "items") -> bytes:
+ from newsroom.agenda.utils import get_related_events # noqa
+
if item_type == "items":
return str.encode(await render_template("download_item.txt", item=item), "utf-8")
else:
- return str.encode(await render_template("download_agenda.txt", item=item), "utf-8")
+ return str.encode(
+ await render_template("download_agenda.txt", item=item, related_events=await get_related_events(item)),
+ "utf-8",
+ )
diff --git a/newsroom/wire/views.py b/newsroom/wire/views.py
index 7c653cb5e..498adcd72 100644
--- a/newsroom/wire/views.py
+++ b/newsroom/wire/views.py
@@ -511,6 +511,7 @@ async def copy(args: WireItemRouteArgs, params: ItemActionUrlParams, request: Re
"""Endpoint to copy Wire OR Agenda item(s)"""
from newsroom.agenda import AgendaItemService
+ from newsroom.agenda.utils import get_related_events
item_type = get_type()
service = AgendaItemService() if item_type == "agenda" else WireItemService()
@@ -530,6 +531,7 @@ async def copy(args: WireItemRouteArgs, params: ItemActionUrlParams, request: Re
"location": "" if item_type != "agenda" else get_location_string(item_to_copy),
"contacts": get_public_contacts(item_to_copy),
"calendars": ", ".join([calendar.get("name") for calendar in item_to_copy.get("calendars") or []]),
+ "related_events": await get_related_events(item_to_copy),
}
)
copy_data = (await render_template(template_name, **template_kwargs)).strip()