Skip to content

Commit

Permalink
STT-54: Update download, topic notification, and sharing templates to…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
devketanpro authored Jan 15, 2025
1 parent 1ba1e4d commit c447820
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 6 deletions.
13 changes: 13 additions & 0 deletions newsroom/agenda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion newsroom/agenda/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion newsroom/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions newsroom/templates/agenda_item_print.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,25 @@ <h5>{{ gettext('Coverages:') }}</h5>
{% endif %}
</div>
{% endfor %}
{%- if related_events %}
<div>Related Events:</div>
{%- for event in related_events %}
<div>
{%- if event.name %}
<div>{{ event.name }}</div>
{%- endif %}
{%- if event.slugline %}
<div>Slugline: {{ event.slugline }}</div>
{%- endif %}
{%- if event.headline %}
<div>Headline: {{ event.headline }}</div>
{%- endif %}
{%- if event.definition_long %}
<div>Definition: {{ event.definition_long }}</div>
{%- endif %}
<div>{{ event | format_event_datetime }}</div>
</div>
{%- endfor %}
{%- endif %}
</article>
{% endblock %}
18 changes: 17 additions & 1 deletion newsroom/templates/copy_agenda_item.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ Description: {{ plan.description_text | plain_text }}
{% endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endif -%}
{%- 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 %}
18 changes: 17 additions & 1 deletion newsroom/templates/download_agenda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,20 @@
{% if coverage.workflow_status %} Workflow Status: {{ coverage.workflow_status }}
{% endif -%}
Coverage Status: {{ coverage.coverage_status }}
{%- endfor %}{% endif %}
{%- 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 %}
20 changes: 20 additions & 0 deletions newsroom/templates/email_agenda.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ <h3>Planning item:</h3>
{% endif %}
</div>
{% endfor %}

{% if related_events %}
<p>Related Events:</p>
{% for event in related_events %}
<div>
{% if event.name %}
<div>{{ event.name }}</div>
{% endif %}
{% if event.slugline %}
<div>Slugline: {{ event.slugline }}</div>
{% endif %}
{% if event.headline %}
<div>Headline: {{ event.headline }}</div>
{% endif %}
{% if event.definition_long %}
<div>{{ event.definition_long }}</div>
{% endif %}
</div>
{% endfor %}
{% endif %}
16 changes: 15 additions & 1 deletion newsroom/templates/email_agenda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
{% 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 %}
7 changes: 6 additions & 1 deletion newsroom/wire/formatters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
2 changes: 2 additions & 0 deletions newsroom/wire/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit c447820

Please sign in to comment.