Hi Collin,
On 17/11/14 21:19, Collin Anderson wrote:
Hi Alasdair,
I'm upgrading to Django 1.7, and updating my forms to use the new
form.add_errors() method.
I have one remaining pattern which uses form._errors.
class MyForm(forms.Form):
...
def clean():
cleaned_data = super(MyForm, self).clean()
if not self._errors:
do_something()
I only want to call do_something() if no errors have been found during
the validation so far. I'd rather not use self._errors, since it is now
a private API according to the release notes [1]. What's the
recommended
way to replace self._errors here?
Is it ok to use self.errors instead? Looking at the source code [2],
errors is a property, not an attribute. By the time the clean() method
is called, self._errors should have been created, so I think that
accessing self.errors should be safe.
The doc says it's ok.
"Since the field validation methods have been run by the time clean() is
called, you also have access to the form’s errors attribute which
contains all the errors raised by cleaning of individual fields."
https://docs.djangoproject.com/en/dev/ref/forms/validation/#form-subclasses-and-modifying-field-errors
Thanks for your reply, and your link to the docs. I can go ahead and
replace my occurrences of self._errors with self.errors with confidence :)
Cheers,
Alasdair
--
Alasdair Nicol
Developer, MEMSET
mail: alasd...@memset.com
web: http://www.memset.com/
Memset Ltd., registration number 4504980.
Building 87, Dunsfold Park, Stovolds Hill, Cranleigh, Surrey, GU6 8TB, UK
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/546E0B87.7050001%40memset.com.
For more options, visit https://groups.google.com/d/optout.