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


Python ErrorList.extend方法代碼示例

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


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

示例1: clean

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def clean(self, value):
        clean_data = []
        errors = ErrorList()
        if not value or isinstance(value, (list, tuple)):
            if not value or not [v for v in value if v not in self.empty_values]:
                if self.required:
                    raise ValidationError(self.error_messages['required'])
                else:
                    return []
        else:
            raise ValidationError(self.error_messages['invalid'])
        
        for field_value in value:
            try:
                clean_data.append(self.contained_field.clean(field_value))
            except ValidationError as e:
                # Collect all validation errors in a single list, which we'll
                # raise at the end of clean(), rather than raising a single
                # exception for the first error we encounter.
                errors.extend(e.messages)
            if self.contained_field.required:
                self.contained_field.required = False
        if errors:
            raise ValidationError(errors)

        self.validate(clean_data)
        self.run_validators(clean_data)
        return clean_data
開發者ID:hdzierz,項目名稱:Kaka,代碼行數:30,代碼來源:fields.py

示例2: clean

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def clean(self, value):
        """
        We clean every subwidget.
        """
        clean_data = []
        errors = ErrorList()
        is_empty = not value or not [v for v in value if v not in self.empty_values]
        if is_empty and not self.required:
            return []

        if is_empty and self.required:
            raise ValidationError(self.error_messages['required'])

        if value and not isinstance(value, (list, tuple)):
            raise ValidationError(self.error_messages['invalid'])

        for field_value, checkbox_value in value:
            try:
                clean_data.append([self.contained_field.clean(field_value), checkbox_value])
            except ValidationError as e:
                errors.extend(e.messages)
            # FIXME: copy paste from above
            if self.contained_field.required:
                self.contained_field.required = False
        if errors:
            raise ValidationError(errors)

        self.validate(clean_data)
        self.run_validators(clean_data)
        return clean_data
開發者ID:Work4Labs,項目名稱:django-mongodbforms,代碼行數:32,代碼來源:fields.py

示例3: get_error_titles

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
	def get_error_titles(self):
		errors = ErrorList()
		for form in self.formsets:
			for item in form.errors:
				if item:
					errors.extend(item)
		return errors
開發者ID:scrapinghub,項目名稱:django-xadmin,代碼行數:9,代碼來源:edit.py

示例4: clean

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def clean(self, value):
        """
        Validates every value in the given list. A value is validated against
        the corresponding Field in self.fields.

        For example, if this MultiValueField was instantiated with
        fields=(DateField(), TimeField()), clean() would call
        DateField.clean(value[0]) and TimeField.clean(value[1]).
        """
        clean_data = []
        errors = ErrorList()
        if not value or isinstance(value, (list, tuple)):
            if not value or not [v for v in value if v not in self.empty_values]:
                if self.required:
                    raise ValidationError(self.error_messages['required'], code='required')
                else:
                    return self.compress([])
        else:
            raise ValidationError(self.error_messages['invalid'], code='invalid')
        for i, field in enumerate(self.fields):
            try:
                field_value = value[i]
            except IndexError:
                field_value = None
            if field_value in self.empty_values:
                if self.require_all_fields:
                    # Raise a 'required' error if the MultiValueField is
                    # required and any field is empty.
                    if self.required:
                        raise ValidationError(self.error_messages['required'], code='required')
                elif field.required:
                    # Otherwise, add an 'incomplete' error to the list of
                    # collected errors and skip field cleaning, if a required
                    # field is empty.
                    if field.error_messages['incomplete'] not in errors:
                        errors.append(field.error_messages['incomplete'])
                    continue
            try:
                clean_data.append(field.clean(field_value))
            except ValidationError as e:
                # Collect all validation errors in a single list, which we'll
                # raise at the end of clean(), rather than raising a single
                # exception for the first error we encounter. Skip duplicates.
                errors.extend(m for m in e.error_list if m not in errors)
        if errors:
            raise ValidationError(errors)

        out = self.compress(clean_data)
        self.validate(out)
        self.run_validators(out)
        return out
開發者ID:AvaniLodaya,項目名稱:django,代碼行數:53,代碼來源:fields.py

示例5: post

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
 def post(self, request, *args, **kwargs):
     if self.async_response is not None:
         return self.async_response
     if self.subscription_form.is_valid():
         try:
             subscription = self.subscription_form.create_subscription()
             return HttpResponseRedirect(
                 reverse(EditSubscriptionView.urlname, args=(subscription.id,))
             )
         except NewSubscriptionError as e:
             errors = ErrorList()
             errors.extend([e.message])
             self.subscription_form._errors.setdefault(NON_FIELD_ERRORS, errors)
     return self.get(request, *args, **kwargs)
開發者ID:kkrampa,項目名稱:commcare-hq,代碼行數:16,代碼來源:views.py

示例6: clean

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def clean(self, value):
        clean_data = {}
        errors = ErrorList()
        if not value or isinstance(value, dict):
            if not value or not [
                    v for v in value.values() if v not in self.empty_values
            ]:
                if self.required:
                    raise ValidationError(self.error_messages['required'])
                else:
                    return {}
        else:
            raise ValidationError(self.error_messages['invalid'])

        # sort out required => at least one element must be in there
        for key, val in value.items():
            # ignore empties. Can they even come up here?
            if key in self.empty_values and val in self.empty_values:
                continue

            try:
                val = self.contained_field.clean(val)
            except ValidationError as e:
                # Collect all validation errors in a single list, which we'll
                # raise at the end of clean(), rather than raising a single
                # exception for the first error we encounter.
                errors.extend(e.messages)

            try:
                self._validate_key(key)
            except ValidationError as e:
                # Collect all validation errors in a single list, which we'll
                # raise at the end of clean(), rather than raising a single
                # exception for the first error we encounter.
                errors.extend(e.messages)

            clean_data[key] = val

            if self.contained_field.required:
                self.contained_field.required = False

        if errors:
            raise ValidationError(errors)

        self.validate(clean_data)
        self.run_validators(clean_data)
        return clean_data
開發者ID:lucidbard,項目名稱:django-mongodbforms,代碼行數:49,代碼來源:fields.py

示例7: clean

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def clean(self, value):
        """
        This is a copy of MultiValueField.clean() with a BUGFIX:
        -   if self.required and field_value in validators.EMPTY_VALUES:
        +   if field.required and field_value in validators.EMPTY_VALUES:
        """
        try:
            from django.forms.utils import ErrorList
        except ImportError:
            from django.forms.util import ErrorList
        from django.core import validators
        from django.core.exceptions import ValidationError

        clean_data = []
        errors = ErrorList()
        if not value or isinstance(value, (list, tuple)):
            if not value or not [v for v in value if v not in validators.EMPTY_VALUES]:
                if self.required:
                    raise ValidationError(self.error_messages['required'])
                else:
                    return self.compress(value)
        else:
            raise ValidationError(self.error_messages['invalid'])
        for i, field in enumerate(self.fields):
            try:
                field_value = value[i]
            except IndexError:
                field_value = None
            if field.required and field_value in validators.EMPTY_VALUES:
                raise ValidationError(self.error_messages['required'])
            try:
                clean_data.append(field.clean(field_value))
            except ValidationError as e:
                # Collect all validation errors in a single list, which we'll
                # raise at the end of clean(), rather than raising a single
                # exception for the first error we encounter.
                errors.extend(e.messages)
        if errors:
            raise ValidationError(errors)

        out = self.compress(clean_data)
        self.validate(out)
        self.run_validators(out)
        return out
開發者ID:Yuego,項目名稱:django-files-widget,代碼行數:46,代碼來源:fields.py

示例8: clean

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def clean(self, value):
        # Get the value
        # Totally replaced validation.
        clean_data = []
        errors = ErrorList()

        # Only the visible field is required.
        radio_value = value[0]
        field_visible = [False] * len(self.fields)
        field_visible[0] = True
        if radio_value is None:
            # radio_value is None when models are deleted in formsets
            out = ''
        else:
            field_visible[self.url_type_registry.index(radio_value) + 1] = True

            # The validators only fire for visible fields.
            for i, field in enumerate(self.fields):
                try:
                    field_value = value[i]
                except IndexError:
                    field_value = None

                if not field_visible[i]:
                    clean_data.append(None)
                    continue

                if self.required and field_value in validators.EMPTY_VALUES:
                    raise ValidationError(self.error_messages['required'])

                try:
                    clean_data.append(field.clean(field_value))
                except ValidationError as e:
                    errors.extend(e.messages)  # Collect all widget errors
            if errors:
                raise ValidationError(errors)

            out = self.compress(clean_data)

        self.validate(out)
        return out
開發者ID:edoburu,項目名稱:django-any-urlfield,代碼行數:43,代碼來源:fields.py

示例9: hidden_field_errors

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
def hidden_field_errors(form):
    hidden_field_errors = ErrorList()
    for field in form.hidden_fields():
        hidden_field_errors.extend(field.errors)
    return hidden_field_errors
開發者ID:luisrene88,項目名稱:django-kendo-core-ui,代碼行數:7,代碼來源:kendocore.py

示例10: bulk_view

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
    def bulk_view(self, request, form_url='', extra_context=None):
        to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
        if to_field and not self.to_field_allowed(request, to_field):
            raise DisallowedModelAdminToField("The field %s cannot be referenced." % to_field)

        model = self.model
        opts = model._meta

        continue_requested = request.POST.get('_continue', request.GET.get('_continue'))
        force_continue = False
        inline = self.get_bulk_inline(request)
        formset_class = inline.get_formset(request)
        formset_params = {}
        prefix = formset_class.get_default_prefix()
        queryset = inline.get_queryset(request)

        if not self.has_add_permission(request):
            formset_class.max_num = 0

        if request.method == 'GET':
            if 'pks' in request.GET and self.has_change_permission(request):
                pks = [opts.pk.to_python(pk) for pk in request.GET.get('pks').split(',')]
                queryset = queryset.filter(pk__in=pks)
            else:
                queryset = queryset.none()

        elif request.method == 'POST':
            management_form = ManagementForm(request.POST, prefix=prefix)

            if not management_form.is_valid():
                raise ValidationError(
                    _('ManagementForm data is missing or has been tampered with'),
                    code='missing_management_form',
                )

            if not self.has_add_permission(request) and management_form.cleaned_data[INITIAL_FORM_COUNT] < management_form.cleaned_data[TOTAL_FORM_COUNT]:
                raise PermissionDenied

            if not self.has_change_permission(request) and management_form.cleaned_data[INITIAL_FORM_COUNT] > 0:
                raise PermissionDenied

            queryset = self.transform_queryset(request, queryset, management_form, prefix)

            post, files, force_continue = self.transform_post_and_files(request, prefix)
            formset_params.update({
                'data': post,
                'files': files,
            })

        formset_params['queryset'] = queryset

        formset = formset_class(**formset_params)

        if request.method == 'POST':
            if formset.is_valid():
                self.save_formset(request, form=None, formset=formset, change=False)

                if continue_requested or force_continue:
                    # The implementation of ModelAdmin redirects to the change view if valid and continue was requested
                    # The change view then reads the edited model again from database
                    # In our case, we can't make a redirect as we would loose the information which models should be edited
                    # Thus, we create a new formset with the edited models and continue as this would have been a usual GET request

                    if self.has_change_permission(request):
                        queryset = _ListQueryset(queryset)
                        queryset.extend(formset.new_objects)
                    else:
                        queryset = _ListQueryset()

                    formset_params.update({
                        'data': None,
                        'files': None,
                        'queryset': queryset,
                    })

                    formset = formset_class(**formset_params)

                    msg = _('The %s were bulk added successfully. You may edit them again below.') % (force_text(opts.verbose_name_plural),)
                    self.message_user(request, msg, messages.SUCCESS)

                else:
                    return self.response_bulk(request, formset)

        media = self.media

        inline_formsets = self.get_inline_formsets(request, [formset], [inline], obj=None)
        for inline_formset in inline_formsets:
            media = media + inline_formset.media

        errors = ErrorList()

        if formset.is_bound:
            errors.extend(formset.non_form_errors())
            for formset_errors in formset.errors:
                errors.extend(list(six.itervalues(formset_errors)))

        context = dict(
            self.admin_site.each_context(request) if django.VERSION >= (1, 8) else self.admin_site.each_context(),
            bulk=True,
            bulk_formset_prefix=prefix,
#.........這裏部分代碼省略.........
開發者ID:impala2,項目名稱:django-bulk-admin,代碼行數:103,代碼來源:admin.py

示例11: get_error_list

# 需要導入模塊: from django.forms.utils import ErrorList [as 別名]
# 或者: from django.forms.utils.ErrorList import extend [as 別名]
	def get_error_list(self):
		errors = ErrorList()
		if self.form_obj.is_bound:
			errors.extend(self.form_obj.errors.values())
		return errors
開發者ID:scrapinghub,項目名稱:django-xadmin,代碼行數:7,代碼來源:edit.py


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