當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.ErrorDict方法代碼示例

本文整理匯總了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() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:forms.py

示例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() 
開發者ID:inventree,項目名稱:InvenTree,代碼行數:18,代碼來源:forms.py

示例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()) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:test_utils.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:26,代碼來源:tests.py

示例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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:forms.py

示例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} 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:8,代碼來源:forms.py

示例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) 
開發者ID:Cadasta,項目名稱:cadasta-platform,代碼行數:12,代碼來源:test_forms.py

示例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__()) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:test_utils.py


注:本文中的django.forms.utils.ErrorDict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。