Python django.forms.utils.ErrorDict() Examples
The following are 10
code examples of django.forms.utils.ErrorDict().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.forms.utils
, or try the search function
.
Example #1
Source File: forms.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def full_clean(self): """ Cleans all of self.data and populates self._errors and self.cleaned_data. """ self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return self._clean_fields() self._clean_form() self._post_clean()
Example #2
Source File: forms.py From InvenTree with MIT License | 6 votes |
def full_clean(self): self._errors = ErrorDict() if not self.is_bound: # Stop further processing. return self.cleaned_data = {} # If the form is permitted to be empty, and none of the form data has # changed from the initial data, short circuit any validation. if self.empty_permitted and not self.has_changed(): return # Don't run _post_clean() as this will run StockItem.clean() self._clean_fields() self._clean_form()
Example #3
Source File: test_utils.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_error_dict_copy(self): e = ErrorDict() e['__all__'] = ErrorList([ ValidationError( message='message %(i)s', params={'i': 1}, ), ValidationError( message='message %(i)s', params={'i': 2}, ), ]) e_copy = copy.copy(e) self.assertEqual(e, e_copy) self.assertEqual(e.as_data(), e_copy.as_data()) e_deepcopy = copy.deepcopy(e) self.assertEqual(e, e_deepcopy) self.assertEqual(e.as_data(), e_copy.as_data())
Example #4
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_error_class(self): ''' Test the type of Formset and Form error attributes ''' Formset = modelformset_factory(User, fields="__all__") data = { 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MAX_NUM_FORMS': '0', 'form-0-id': '', 'form-0-username': 'apollo13', 'form-0-serial': '1', 'form-1-id': '', 'form-1-username': 'apollo13', 'form-1-serial': '2', } formset = Formset(data) # check if the returned error classes are correct # note: formset.errors returns a list as documented self.assertIsInstance(formset.errors, list) self.assertIsInstance(formset.non_form_errors(), ErrorList) for form in formset.forms: self.assertIsInstance(form.errors, ErrorDict) self.assertIsInstance(form.non_field_errors(), ErrorList)
Example #5
Source File: test_utils.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_error_dict_copy(self): e = ErrorDict() e['__all__'] = ErrorList([ ValidationError( message='message %(i)s', params={'i': 1}, ), ValidationError( message='message %(i)s', params={'i': 2}, ), ]) e_copy = copy.copy(e) self.assertEqual(e, e_copy) self.assertEqual(e.as_data(), e_copy.as_data()) e_deepcopy = copy.deepcopy(e) self.assertEqual(e, e_deepcopy) self.assertEqual(e.as_data(), e_copy.as_data())
Example #6
Source File: forms.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def errors(self): "Returns an ErrorDict for the data provided for the form" if self._errors is None: self.full_clean() return self._errors
Example #7
Source File: forms.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def full_clean(self): if self.data.get(self.prefix + '-remove') != 'on': super().full_clean() else: self._errors = ErrorDict() self.cleaned_data = {'remove': True}
Example #8
Source File: test_forms.py From cadasta-platform with GNU Affero General Public License v3.0 | 5 votes |
def test_full_clean_remove(self): data = { 'contacts-name': 'John', 'contacts-email': 'john@beatles.uk', 'contacts-remove': 'on' } form = forms.ContactsForm(data=data, prefix='contacts') form.full_clean() assert form.cleaned_data == {'remove': True} assert isinstance(form._errors, ErrorDict)
Example #9
Source File: test_utils.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_error_dict_html_safe(self): e = ErrorDict() e['username'] = 'Invalid username.' self.assertTrue(hasattr(ErrorDict, '__html__')) self.assertEqual(str(e), e.__html__())
Example #10
Source File: test_utils.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_error_dict_html_safe(self): e = ErrorDict() e['username'] = 'Invalid username.' self.assertTrue(hasattr(ErrorDict, '__html__')) self.assertEqual(str(e), e.__html__())