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


Python Form.clean方法代碼示例

本文整理匯總了Python中django.forms.Form.clean方法的典型用法代碼示例。如果您正苦於以下問題:Python Form.clean方法的具體用法?Python Form.clean怎麽用?Python Form.clean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms.Form的用法示例。


在下文中一共展示了Form.clean方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_valid

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def is_valid(self):
        """Return True if every form in self.forms is valid."""
        if not self.is_bound:
            return False
        # We loop over every form.errors here rather than short circuiting on the
        # first failure to make sure validation gets triggered for every form.
        forms_valid = True
        # This triggers a full clean.
        self.errors
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            if self.can_delete and self._should_delete_form(form):
                # This form is going to be deleted so any of its errors
                # shouldn't cause the entire formset to be invalid.
                continue
            forms_valid &= form.is_valid()
        return forms_valid and not self.non_form_errors() 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:19,代碼來源:formsets.py

示例2: is_valid

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def is_valid(self):
        """
        Returns True if every form in self.forms is valid.
        """
        if not self.is_bound:
            return False
        # We loop over every form.errors here rather than short circuiting on the
        # first failure to make sure validation gets triggered for every form.
        forms_valid = True
        # This triggers a full clean.
        self.errors
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            if self.can_delete:
                if self._should_delete_form(form):
                    # This form is going to be deleted so any of its errors
                    # should not cause the entire formset to be invalid.
                    continue
            forms_valid &= form.is_valid()
        return forms_valid and not self.non_form_errors() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:22,代碼來源:formsets.py

示例3: non_form_errors

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def non_form_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        form -- i.e., from formset.clean(). Returns an empty ErrorList if there
        are none.
        """
        if self._non_form_errors is None:
            self.full_clean()
        return self._non_form_errors 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:11,代碼來源:formsets.py

示例4: full_clean

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def full_clean(self):
        """
        Cleans all of self.data and populates self._errors and
        self._non_form_errors.
        """
        self._errors = []
        self._non_form_errors = self.error_class()

        if not self.is_bound:  # Stop further processing.
            return
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            self._errors.append(form.errors)
        try:
            if (self.validate_max and
                    self.total_form_count() - len(self.deleted_forms) > self.max_num) or \
                    self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max:
                raise ValidationError(ungettext(
                    "Please submit %d or fewer forms.",
                    "Please submit %d or fewer forms.", self.max_num) % self.max_num,
                    code='too_many_forms',
                )
            if (self.validate_min and
                    self.total_form_count() - len(self.deleted_forms) < self.min_num):
                raise ValidationError(ungettext(
                    "Please submit %d or more forms.",
                    "Please submit %d or more forms.", self.min_num) % self.min_num,
                    code='too_few_forms')
            # Give self.clean() a chance to do cross-form validation.
            self.clean()
        except ValidationError as e:
            self._non_form_errors = self.error_class(e.error_list) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:34,代碼來源:formsets.py

示例5: clean

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def clean(self):
        """
        Hook for doing any extra formset-wide cleaning after Form.clean() has
        been called on every form. Any ValidationError raised by this method
        will not be associated with a particular form; it will be accessible
        via formset.non_form_errors()
        """
        pass 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:formsets.py

示例6: non_form_errors

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def non_form_errors(self):
        """
        Return an ErrorList of errors that aren't associated with a particular
        form -- i.e., from formset.clean(). Return an empty ErrorList if there
        are none.
        """
        if self._non_form_errors is None:
            self.full_clean()
        return self._non_form_errors 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:11,代碼來源:formsets.py

示例7: full_clean

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def full_clean(self):
        """
        Clean all of self.data and populate self._errors and
        self._non_form_errors.
        """
        self._errors = []
        self._non_form_errors = self.error_class()
        empty_forms_count = 0

        if not self.is_bound:  # Stop further processing.
            return
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            # Empty forms are unchanged forms beyond those with initial data.
            if not form.has_changed() and i >= self.initial_form_count():
                empty_forms_count += 1
            # Accessing errors calls full_clean() if necessary.
            # _should_delete_form() requires cleaned_data.
            form_errors = form.errors
            if self.can_delete and self._should_delete_form(form):
                continue
            self._errors.append(form_errors)
        try:
            if (self.validate_max and
                    self.total_form_count() - len(self.deleted_forms) > self.max_num) or \
                    self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max:
                raise ValidationError(ngettext(
                    "Please submit %d or fewer forms.",
                    "Please submit %d or fewer forms.", self.max_num) % self.max_num,
                    code='too_many_forms',
                )
            if (self.validate_min and
                    self.total_form_count() - len(self.deleted_forms) - empty_forms_count < self.min_num):
                raise ValidationError(ngettext(
                    "Please submit %d or more forms.",
                    "Please submit %d or more forms.", self.min_num) % self.min_num,
                    code='too_few_forms')
            # Give self.clean() a chance to do cross-form validation.
            self.clean()
        except ValidationError as e:
            self._non_form_errors = self.error_class(e.error_list) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:43,代碼來源:formsets.py

示例8: full_clean

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def full_clean(self):
        """
        Cleans all of self.data and populates self._errors and
        self._non_form_errors.
        """
        self._errors = []
        self._non_form_errors = self.error_class()
        empty_forms_count = 0

        if not self.is_bound:  # Stop further processing.
            return
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            # Empty forms are unchanged forms beyond those with initial data.
            if not form.has_changed() and i >= self.initial_form_count():
                empty_forms_count += 1

            self._errors.append(form.errors)
        try:
            if (self.validate_max and
                    self.total_form_count() - len(self.deleted_forms) > self.max_num) or \
                    self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max:
                raise ValidationError(ungettext(
                    "Please submit %d or fewer forms.",
                    "Please submit %d or fewer forms.", self.max_num) % self.max_num,
                    code='too_many_forms',
                )
            if (self.validate_min and
                    self.total_form_count() - len(self.deleted_forms) - empty_forms_count < self.min_num):
                raise ValidationError(ungettext(
                    "Please submit %d or more forms.",
                    "Please submit %d or more forms.", self.min_num) % self.min_num,
                    code='too_few_forms')
            # Give self.clean() a chance to do cross-form validation.
            self.clean()
        except ValidationError as e:
            self._non_form_errors = self.error_class(e.error_list) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:39,代碼來源:formsets.py

示例9: non_form_errors

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def non_form_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        form -- i.e., from formset.clean(). Returns an empty ErrorList if there
        are none.
        """
        if self._non_form_errors is not None:
            return self._non_form_errors
        return self.error_class() 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:11,代碼來源:formsets.py

示例10: full_clean

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def full_clean(self):
        """
        Cleans all of self.data and populates self._errors.
        """
        self._errors = []
        if not self.is_bound: # Stop further processing.
            return
        for i in range(0, self.total_form_count()):
            form = self.forms[i]
            self._errors.append(form.errors)
        # Give self.clean() a chance to do cross-form validation.
        try:
            self.clean()
        except ValidationError as e:
            self._non_form_errors = self.error_class(e.messages) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:17,代碼來源:formsets.py

示例11: clean

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import clean [as 別名]
def clean(self):
        """
        Hook for doing any extra formset-wide cleaning after Form.clean() has
        been called on every form. Any ValidationError raised by this method
        will not be associated with a particular form; it will be accesible
        via formset.non_form_errors()
        """
        pass 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:10,代碼來源:formsets.py


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