0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

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
This commit is contained in:
Matt Westcott 2017-03-13 14:27:07 +00:00 committed by Janneke Janssen
parent 4a5714d5c7
commit 8b57a46ecc
2 changed files with 7 additions and 4 deletions

View File

@ -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', '<li>{}</li>', ((e,) for e in all_errors))
full_message = format_html("""{} <ul class="errorlist">{}</ul>""", message, errors_html)
detail = format_html("""<ul class="errorlist">{}</ul>""", 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):

View File

@ -7,3 +7,5 @@
{% endfor %}
</span>
{% endif %}
{{ detail }}