Skip to content

Commit

Permalink
Assignment mails - Language specific mail based on the language of th…
Browse files Browse the repository at this point in the history
…e coverage [SDBELGA-866] (#2071)

* Assignment mails - Language specific mail based on the language of the coverage [SDBELGA-866]

* minor change
  • Loading branch information
devketanpro authored Aug 28, 2024
1 parent a45af31 commit e82f581
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/planning/assignments/assignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
from planning.common import format_address, get_assginment_name
from apps.content import push_content_notification
from .assignments_history import ASSIGNMENT_HISTORY_ACTIONS
from planning.utils import get_event_formatted_dates, get_formatted_contacts
from planning.utils import get_event_formatted_dates, get_formatted_contacts, update_event_item_with_translations_value
from superdesk.preferences import get_user_notification_preferences

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -472,6 +472,12 @@ def send_assignment_notification(self, updates, original=None, force=False):
formatted_contacts = get_formatted_contacts(event_item) if event_item else []
fomatted_event_date = get_event_formatted_dates(event_item) if event_item else ""

event_item = (
update_event_item_with_translations_value(event_item, assignment.get("planning", {}).get("language"))
if event_item
else None
)

# The assignment is to an external contact or a user
if assigned_to.get("contact") or assigned_to.get("user"):
# If it is a reassignment
Expand Down
11 changes: 11 additions & 0 deletions server/planning/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ def get_event_formatted_dates(event: Dict[str, Any]) -> str:
return "{} {}".format(time_short(start, tz), date_short(start, tz))

return "{} - {}, {}".format(time_short(start, tz), time_short(end, tz), date_short(start, tz))


def update_event_item_with_translations_value(event_item: Dict[str, Any], language: str) -> Dict[str, Any]:
if not event_item.get("translations") or not language:
return event_item
updated_event_item = event_item.copy()
for translation in event_item["translations"]:
if translation["language"] == language:
updated_event_item[translation["field"]] = translation["value"]

return updated_event_item

0 comments on commit e82f581

Please sign in to comment.