mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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 <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
5f8d3e30d0
commit
fee21cba0d
@ -10,14 +10,14 @@
|
||||
</div>
|
||||
|
||||
<p>
|
||||
{% 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
|
||||
<a href="{{ url }}">release announcement</a>.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="{% url 'notification_dismiss' id='upgrades-new-release' %}?next={{ request.path|iriencode }}"
|
||||
<a href="{% url 'notification_dismiss' id=id %}?next={{ request.path|iriencode }}"
|
||||
role="button" class="btn btn-default">
|
||||
{% trans "Dismiss" %}
|
||||
</a>
|
||||
|
||||
@ -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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user