summaryrefslogtreecommitdiff
path: root/django/forms/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/forms/utils.py')
-rw-r--r--django/forms/utils.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/django/forms/utils.py b/django/forms/utils.py
index f7f53e9a0a..14253f36fe 100644
--- a/django/forms/utils.py
+++ b/django/forms/utils.py
@@ -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))
)