本文整理汇总了Python中django.forms.utils.ErrorDict方法的典型用法代码示例。如果您正苦于以下问题:Python utils.ErrorDict方法的具体用法?Python utils.ErrorDict怎么用?Python utils.ErrorDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.utils
的用法示例。
在下文中一共展示了utils.ErrorDict方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: full_clean
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
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()
示例2: full_clean
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
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()
示例3: test_error_dict_copy
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
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())
示例4: test_error_class
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
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)
示例5: errors
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
def errors(self):
"Returns an ErrorDict for the data provided for the form"
if self._errors is None:
self.full_clean()
return self._errors
示例6: full_clean
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
def full_clean(self):
if self.data.get(self.prefix + '-remove') != 'on':
super().full_clean()
else:
self._errors = ErrorDict()
self.cleaned_data = {'remove': True}
示例7: test_full_clean_remove
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
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)
示例8: test_error_dict_html_safe
# 需要导入模块: from django.forms import utils [as 别名]
# 或者: from django.forms.utils import ErrorDict [as 别名]
def test_error_dict_html_safe(self):
e = ErrorDict()
e['username'] = 'Invalid username.'
self.assertTrue(hasattr(ErrorDict, '__html__'))
self.assertEqual(str(e), e.__html__())