From 8b57a46ecc43440fd3cb9b7ca23357f02ff14095 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Mon, 13 Mar 2017 14:27:07 +0000 Subject: [PATCH] Add a separate 'detail' section to message rendering This allows us to include block-level content (such as a list of validation errors) into the message without breaking the positioning of buttons - see https://github.com/wagtail/wagtail/pull/3440#discussion_r105564633 --- wagtail/wagtailadmin/messages.py | 9 +++++---- .../templates/wagtailadmin/shared/messages.html | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/wagtail/wagtailadmin/messages.py b/wagtail/wagtailadmin/messages.py index 30703cf678..a1b0c95c72 100644 --- a/wagtail/wagtailadmin/messages.py +++ b/wagtail/wagtailadmin/messages.py @@ -6,10 +6,11 @@ from django.template.loader import render_to_string from django.utils.html import format_html, format_html_join -def render(message, buttons): +def render(message, buttons, detail=''): return render_to_string('wagtailadmin/shared/messages.html', { 'message': message, 'buttons': buttons, + 'detail': detail, }) @@ -37,7 +38,7 @@ def validation_error(request, message, form, buttons=None): if not form.non_field_errors(): # just output the generic "there were validation errors" message, and leave # the per-field highlighting to do the rest - full_message = message + detail = '' else: # display the full list of field and non-field validation errors all_errors = [] @@ -55,9 +56,9 @@ def validation_error(request, message, form, buttons=None): all_errors.append(prefix + error) errors_html = format_html_join('\n', '
  • {}
  • ', ((e,) for e in all_errors)) - full_message = format_html("""{} """, message, errors_html) + detail = format_html("""""", errors_html) - return messages.error(request, render(full_message, buttons)) + return messages.error(request, render(message, buttons, detail=detail)) def button(url, text, new_window=False): diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/shared/messages.html b/wagtail/wagtailadmin/templates/wagtailadmin/shared/messages.html index a23ee3efae..0fca3b2857 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/shared/messages.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/shared/messages.html @@ -7,3 +7,5 @@ {% endfor %} {% endif %} + +{{ detail }}