diff options
| author | François Freitag <mail@franek.fr> | 2020-02-12 14:48:49 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-28 10:49:00 +0200 |
| commit | 9ef4a18dbe71f538a9ef8c39111ae2f0b62eb90b (patch) | |
| tree | 0016b13a357af2f642483bdd168d6f83190f33bb /docs | |
| parent | 2788de95e375cccd03a3dfd161fc92b7d6df6024 (diff) | |
Changed django.forms.ValidationError imports to django.core.exceptions.ValidationError.
Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/fields.txt | 5 | ||||
| -rw-r--r-- | docs/ref/forms/validation.txt | 6 | ||||
| -rw-r--r-- | docs/topics/auth/customizing.txt | 3 | ||||
| -rw-r--r-- | docs/topics/auth/default.txt | 4 | ||||
| -rw-r--r-- | docs/topics/forms/formsets.txt | 5 | ||||
| -rw-r--r-- | docs/topics/i18n/translation.txt | 5 |
6 files changed, 17 insertions, 11 deletions
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index 92c1af63d7..3d228e88ad 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -18,8 +18,9 @@ other hooks. Although the primary way you'll use ``Field`` classes is in ``Form`` classes, you can also instantiate them and use them directly to get a better idea of how they work. Each ``Field`` instance has a ``clean()`` method, which takes -a single argument and either raises a ``django.forms.ValidationError`` -exception or returns the clean value:: +a single argument and either raises a +``django.core.exceptions.ValidationError`` exception or returns the clean +value:: >>> from django import forms >>> f = forms.EmailField() diff --git a/docs/ref/forms/validation.txt b/docs/ref/forms/validation.txt index d12232afc7..c3fa968bdb 100644 --- a/docs/ref/forms/validation.txt +++ b/docs/ref/forms/validation.txt @@ -305,6 +305,7 @@ don't want to put it into the general ``MultiEmailField`` class. Instead, we write a cleaning method that operates on the ``recipients`` field, like so:: from django import forms + from django.core.exceptions import ValidationError class ContactForm(forms.Form): # Everything as before. @@ -313,7 +314,7 @@ write a cleaning method that operates on the ``recipients`` field, like so:: def clean_recipients(self): data = self.cleaned_data['recipients'] if "fred@example.com" not in data: - raise forms.ValidationError("You have forgotten about Fred!") + raise ValidationError("You have forgotten about Fred!") # Always return a value to use as the new cleaned data, even if # this method didn't change it. @@ -346,6 +347,7 @@ an error, you can raise a ``ValidationError`` from the ``clean()`` method. For example:: from django import forms + from django.core.exceptions import ValidationError class ContactForm(forms.Form): # Everything as before. @@ -359,7 +361,7 @@ example:: if cc_myself and subject: # Only do something if both fields are valid so far. if "help" not in subject: - raise forms.ValidationError( + raise ValidationError( "Did not send for 'help' in the subject despite " "CC'ing yourself." ) diff --git a/docs/topics/auth/customizing.txt b/docs/topics/auth/customizing.txt index 2bf8d611c2..c8a9a39158 100644 --- a/docs/topics/auth/customizing.txt +++ b/docs/topics/auth/customizing.txt @@ -1100,6 +1100,7 @@ code would be required in the app's ``admin.py`` file:: from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.forms import ReadOnlyPasswordHashField + from django.core.exceptions import ValidationError from customauth.models import MyUser @@ -1119,7 +1120,7 @@ code would be required in the app's ``admin.py`` file:: password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: - raise forms.ValidationError("Passwords don't match") + raise ValidationError("Passwords don't match") return password2 def save(self, commit=True): diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt index 9cebdf4a3e..dab12ca592 100644 --- a/docs/topics/auth/default.txt +++ b/docs/topics/auth/default.txt @@ -1508,12 +1508,12 @@ provides several built-in forms located in :mod:`django.contrib.auth.forms`: class PickyAuthenticationForm(AuthenticationForm): def confirm_login_allowed(self, user): if not user.is_active: - raise forms.ValidationError( + raise ValidationError( _("This account is inactive."), code='inactive', ) if user.username.startswith('b'): - raise forms.ValidationError( + raise ValidationError( _("Sorry, accounts starting with 'b' aren't welcome here."), code='no_b_users', ) diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index d6aafaa8b5..2f3e4403f6 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -220,7 +220,7 @@ this management data, an exception will be raised:: >>> formset.is_valid() Traceback (most recent call last): ... - django.forms.utils.ValidationError: ['ManagementForm data is missing or has been tampered with'] + django.core.exceptions.ValidationError: ['ManagementForm data is missing or has been tampered with'] It is used to keep track of how many form instances are being displayed. If you are adding new forms via JavaScript, you should increment the count fields @@ -261,6 +261,7 @@ Custom formset validation A formset has a ``clean`` method similar to the one on a ``Form`` class. This is where you define your own validation that works at the formset level:: + >>> from django.core.exceptions import ValidationError >>> from django.forms import BaseFormSet >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm @@ -277,7 +278,7 @@ is where you define your own validation that works at the formset level:: ... continue ... title = form.cleaned_data.get('title') ... if title in titles: - ... raise forms.ValidationError("Articles in a set must have distinct titles.") + ... raise ValidationError("Articles in a set must have distinct titles.") ... titles.append(title) >>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet) diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index d038dcd2c5..5fdf8f0a4e 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -454,6 +454,7 @@ integer as the ``number`` argument. Then ``number`` will be looked up in the dictionary under that key during string interpolation. Here's example:: from django import forms + from django.core.exceptions import ValidationError from django.utils.translation import ngettext_lazy class MyForm(forms.Form): @@ -463,7 +464,7 @@ dictionary under that key during string interpolation. Here's example:: def clean(self): # ... if error: - raise forms.ValidationError(self.error_message % {'num': number}) + raise ValidationError(self.error_message % {'num': number}) If the string contains exactly one unnamed placeholder, you can interpolate directly with the ``number`` argument:: @@ -477,7 +478,7 @@ directly with the ``number`` argument:: def clean(self): # ... if error: - raise forms.ValidationError(self.error_message % number) + raise ValidationError(self.error_message % number) Formatting strings: ``format_lazy()`` |
