Author: lukeplant
Date: 2009-09-11 05:47:40 -0500 (Fri, 11 Sep 2009)
New Revision: 11498
Modified:
django/trunk/django/forms/forms.py
django/trunk/tests/regressiontests/forms/error_messages.py
Log:
Fixed #10968 - Form.errors should use Form.error_class.
Thanks for report and initial patch, matehat.
Modified: django/trunk/django/forms/forms.py
===================================================================
--- django/trunk/django/forms/forms.py 2009-09-11 09:42:17 UTC (rev 11497)
+++ django/trunk/django/forms/forms.py 2009-09-11 10:47:40 UTC (rev 11498)
@@ -243,13 +243,13 @@
value = getattr(self, 'clean_%s' % name)()
self.cleaned_data[name] = value
except ValidationError, e:
- self._errors[name] = e.messages
+ self._errors[name] = self.error_class(e.messages)
if name in self.cleaned_data:
del self.cleaned_data[name]
try:
self.cleaned_data = self.clean()
except ValidationError, e:
- self._errors[NON_FIELD_ERRORS] = e.messages
+ self._errors[NON_FIELD_ERRORS] = self.error_class(e.messages)
if self._errors:
delattr(self, 'cleaned_data')
Modified: django/trunk/tests/regressiontests/forms/error_messages.py
===================================================================
--- django/trunk/tests/regressiontests/forms/error_messages.py 2009-09-11
09:42:17 UTC (rev 11497)
+++ django/trunk/tests/regressiontests/forms/error_messages.py 2009-09-11
10:47:40 UTC (rev 11498)
@@ -358,4 +358,42 @@
Traceback (most recent call last):
...
ValidationError: [u'4 IS INVALID CHOICE']
+
+# Subclassing ErrorList #######################################################
+
+>>> from django.utils.safestring import mark_safe
+>>>
+>>> class TestForm(Form):
+... first_name = CharField()
+... last_name = CharField()
+... birthday = DateField()
+...
+... def clean(self):
+... raise ValidationError("I like to be awkward.")
+...
+>>> class CustomErrorList(util.ErrorList):
+... def __unicode__(self):
+... return self.as_divs()
+... def as_divs(self):
+... if not self: return u''
+... return mark_safe(u'<div class="error">%s</div>'
+... % ''.join([u'<p>%s</p>' % e for e in self]))
+...
+
+This form should print errors the default way.
+
+>>> form1 = TestForm({'first_name': 'John'})
+>>> print form1['last_name'].errors
+<ul class="errorlist"><li>This field is required.</li></ul>
+>>> print form1.errors['__all__']
+<ul class="errorlist"><li>I like to be awkward.</li></ul>
+
+This one should wrap error groups in the customized way.
+
+>>> form2 = TestForm({'first_name': 'John'}, error_class=CustomErrorList)
+>>> print form2['last_name'].errors
+<div class="error"><p>This field is required.</p></div>
+>>> print form2.errors['__all__']
+<div class="error"><p>I like to be awkward.</p></div>
+
"""
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---