From fee21cba0d841282f7b4bfebf40982ef5c2fe961 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 30 Jul 2022 15:37:26 -0700 Subject: [PATCH] notification: Pass full context when rendering body template - Important information such as id of the notification should be available when rendering the body template. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- .../upgrades/templates/upgrades-new-release.html | 4 ++-- plinth/notification.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/plinth/modules/upgrades/templates/upgrades-new-release.html b/plinth/modules/upgrades/templates/upgrades-new-release.html index 66832ad0a..d5fae3c3d 100644 --- a/plinth/modules/upgrades/templates/upgrades-new-release.html +++ b/plinth/modules/upgrades/templates/upgrades-new-release.html @@ -10,14 +10,14 @@

- {% blocktrans trimmed with url="https://discuss.freedombox.org/c/announcements/7" %} + {% blocktrans trimmed with url="https://discuss.freedombox.org/c/announcements/7" version=data.version %} {{ box_name }} has been updated to version {{ version }}. See the release announcement. {% endblocktrans %}

- {% trans "Dismiss" %} diff --git a/plinth/notification.py b/plinth/notification.py index 9917e33e1..cc733d778 100644 --- a/plinth/notification.py +++ b/plinth/notification.py @@ -316,12 +316,13 @@ class Notification(models.StoredNotification): return new_dict @staticmethod - def _render(request, template, data): + def _render(request, template, context): """Use the template name and render it.""" if not template: return None - context = dict(data, box_name=gettext(cfg.box_name), request=request) + context = dict(context, box_name=gettext(cfg.box_name), + request=request) try: return SimpleTemplateResponse(template, context).render() except TemplateDoesNotExist: @@ -345,14 +346,12 @@ class Notification(models.StoredNotification): action['text'] = Notification._translate( action['text'], data) - body = Notification._render(request, note.body_template, data) - notes.append({ + note_context = { 'id': note.id, 'app_id': note.app_id, 'severity': note.severity, 'title': Notification._translate(note.title, data), 'message': Notification._translate(note.message, data), - 'body': body, 'actions': actions, 'data': data, 'created_time': note.created_time, @@ -360,6 +359,10 @@ class Notification(models.StoredNotification): 'user': note.user, 'group': note.group, 'dismissed': note.dismissed, - }) + } + body = Notification._render(request, note.body_template, + note_context) + note_context['body'] = body + notes.append(note_context) return {'notifications': notes, 'max_severity': max_severity}