1
0
mirror of https://github.com/django/django.git synced 2025-10-28 16:16:12 +00:00

Fixed #11776 -- Added CSS class for non-field/top of form errors.

Thanks Daniel Pope for the suggestion.
This commit is contained in:
Nick Presta
2014-04-14 23:58:51 -04:00
committed by Tim Graham
parent a00efa30d6
commit 11f0899bbe
10 changed files with 120 additions and 17 deletions

View File

@@ -80,6 +80,14 @@ class ErrorList(UserList, list):
"""
A collection of errors that knows how to display itself in various formats.
"""
def __init__(self, initlist=None, error_class=None):
super(ErrorList, self).__init__(initlist)
if error_class is None:
self.error_class = 'errorlist'
else:
self.error_class = 'errorlist {}'.format(error_class)
def as_data(self):
return ValidationError(self.data).error_list
@@ -99,8 +107,10 @@ class ErrorList(UserList, list):
def as_ul(self):
if not self.data:
return ''
return format_html(
'<ul class="errorlist">{0}</ul>',
'<ul class="{0}">{1}</ul>',
self.error_class,
format_html_join('', '<li>{0}</li>', ((force_text(e),) for e in self))
)