当前位置: 首页>>代码示例>>Python>>正文


Python ErrorList.extend方法代码示例

本文整理汇总了Python中django.forms.util.ErrorList.extend方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorList.extend方法的具体用法?Python ErrorList.extend怎么用?Python ErrorList.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms.util.ErrorList的用法示例。


在下文中一共展示了ErrorList.extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.ErrorList import extend [as 别名]
 def clean(self, value):
     '''\
     value is assumed to be a dictionary of values with keys corresponding
     to the ones in self.subfields. Each value is validated against it's 
     corresponding field.
     '''
     clean_data = {}
     errors = ErrorList()
     
     if value is None:
         return value
     
     if not isinstance(value, dict):
         raise ValidationError(self.error_messages['invalid'])
     
     for fieldname, field in self.subfields.items():
         if not fieldname in value.keys():
             if field.required:
                 raise ValidationError(field.error_messages['required'])
             else:
                 continue
         
         try:
             clean_data[fieldname] = field.clean(value[fieldname])
         except ValidationError, e:
             errors.extend(e.messages)
开发者ID:luisfreitas07,项目名称:Cetacean-Injuries-Database,代码行数:28,代码来源:forms.py

示例2: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.ErrorList import extend [as 别名]
    def clean(self, value):
        clean_data = []
        errors = ErrorList()

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

        for i, field in enumerate(self.fields):
            try:
                field_value = value[i]
            except IndexError:
                field_value = None

            if field_value in validators.EMPTY_VALUES:
                if (self.required and not self.optional):
                    raise ValidationError(self.error_messages['required'])
            else:
                field_value = field_value
                try:
                    clean_data.append(field.clean(field_value))
                except ValidationError, e:
                    errors.extend(e.messages)

            if i == len(self.fields) and len(clean_data) == 0:
                raise ValidationError(self.error_messages['optional_required'])
开发者ID:barszczmm,项目名称:django-hybrid-filefield,代码行数:27,代码来源:forms.py

示例3: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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 validators.EMPTY_VALUES]:
                if self.required:
                    raise ValidationError(self.error_messages["required"])
                else:
                    return self.compress([])
        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 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, 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)
开发者ID:tovenja,项目名称:django,代码行数:35,代码来源:fields.py

示例4: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.ErrorList import extend [as 别名]
    def clean(self, value):
        """
        Only the default language should be required.
        """
        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([])
        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 i == 0 and 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:
                # 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:geonition,项目名称:geoforms,代码行数:37,代码来源:fields.py

示例5: clean_sub_fields

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.ErrorList import extend [as 别名]
 def clean_sub_fields(self, value):
     """'value' being the list of the values of the subfields, validate
     each subfield."""
     clean_data = []
     errors = ErrorList()
     # Remove the field corresponding to the SKIP_CHECK_NAME boolean field
     # if required.
     fields = self.fields if not self.skip_check else self.fields[:-1]
     for index, field in enumerate(fields):
         try:
             field_value = value[index]
         except IndexError:
             field_value = None
         # Check the field's 'required' field instead of the global
         # 'required' field to allow subfields to be required or not.
         if field.required and field_value in validators.EMPTY_VALUES:
             errors.append(
                 '%s: %s' % (field.label, self.error_messages['required']))
             continue
         try:
             clean_data.append(field.clean(field_value))
         except ValidationError, 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(
                 ['%s: %s' % (field.label, message)
                 for message in e.messages])
开发者ID:deepakhajare,项目名称:maas,代码行数:30,代码来源:config_forms.py

示例6: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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
        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, e:
                errors.extend(e.messages)  # Collect all widget errors
开发者ID:jjanssen,项目名称:django-any-urlfield,代码行数:32,代码来源:fields.py

示例7: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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'])
        
        field = self.field_type(required=self.required)
        for field_value in value:
            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 field.required:
                field.required = False
        if errors:
            raise ValidationError(errors)

        self.validate(clean_data)
        self.run_validators(clean_data)
        return clean_data
开发者ID:Karmak23,项目名称:django-mongodbforms,代码行数:31,代码来源:fields.py

示例8: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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, 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
        
        data_field = self.field_type(**self.field_kwargs)
        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 = data_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 data_field.required:
                data_field.required = False
                
        if errors:
            raise ValidationError(errors)

        self.validate(clean_data)
        self.run_validators(clean_data)
        return clean_data
开发者ID:Jaidan,项目名称:django-mongodbforms,代码行数:57,代码来源:fields.py

示例9: post

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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(ManageBillingAccountView.urlname, args=(subscription.account.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,代码行数:14,代码来源:views.py

示例10: lib_main

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.ErrorList import extend [as 别名]
def lib_main(request):
    albums = []
    errors = ErrorList()

    pager = Paginator([], 1)
    selected_page = 1

    form = None  # it's our search form
    # If a form was just submitted
    if request.method == 'POST':
        form = SearchForm(request.POST)  # A form bound to the POST data
        if form.is_valid():
            # Use the form fields to search and filter albums from the db
            albums = lib_main_filter_albums(form)

            pager = Paginator(albums, form.cleaned_data['items_per_page'])
            selected_page = int(form.cleaned_data['selected_page'])

            page_list = [(str(x), str(x)) for x in pager.page_range][:100]
            if len(page_list) is 0:
                form.fields['selected_page'][('1', '1')]
            else:
                form.fields['selected_page'].choices = page_list
            form.fields['selected_page'].initial = selected_page
        else:
            # Add all of the errors in the form.errors dict to our error list
            errors.extend(chain.from_iterable(form.errors.values()))
        form.save()
    else:
        form = SearchForm(initial={'artist': request.GET.get('artist'),
                                   'album': request.GET.get('album'),
                                   'label': request.GET.get('label'),
                                   'year': request.GET.get('year'),
                                   'genre': request.GET.get('genre'),
                                   'stack': request.GET.get('stack'),
                                   'selected_page': "1",
                                   'items_per_page': "25",
                                   })
        form.fields['selected_page'].choices = [(str(x), str(x)) for x in pager.page_range][:100]

    albums_page = []
    try:
        albums_page = pager.page(selected_page).object_list
    except EmptyPage:
        albums_page = pager.page(1).object_list
        errors.append("That page is empty.")

    return render_to_response('library.html', {
        'form': form,
        'albums': albums_page,
        'errors': errors,
    }, context_instance=RequestContext(request))
开发者ID:cvializ,项目名称:wuvtdb,代码行数:54,代码来源:views.py

示例11: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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:JJZMadTrak,项目名称:django,代码行数:53,代码来源:fields.py

示例12: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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.

        Only allows for exactly 1 valid value to be submitted, this is what
        gets returned by compress.

        example to use directy (instead of using FileOrURLField):
            MutuallyExclusiveValueField(
                fields=(forms.IntegerField(), forms.IntegerField()),
                widget=MutuallyExclusiveRadioWidget(widgets=[
                        forms.Select(choices=[(1,1), (2,2)]),
                        forms.TextInput(attrs={'placeholder':
                                               'Enter a number'}),
                    ]))
        """
        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
            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:mattcaldwell,项目名称:django-xor-formfields,代码行数:51,代码来源:fields.py

示例13: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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:
        """
        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:opendream,项目名称:polygraph,代码行数:45,代码来源:fields.py

示例14: clean_product_rates

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.ErrorList import extend [as 别名]
 def clean_product_rates(self):
     original_data = self.cleaned_data['product_rates']
     rates = json.loads(original_data)
     rate_instances = []
     errors = ErrorList()
     for rate_data in rates:
         rate_form = ProductRateForm(rate_data)
         if not rate_form.is_valid():
             errors.extend(list(self._get_errors_from_subform(rate_data['name'], rate_form)))
         else:
             rate_instances.append(self._retrieve_product_rate(rate_form))
     if errors:
         self._errors.setdefault('product_rates', errors)
     self.new_product_rates = rate_instances
     rate_ids = lambda x: set([r.id for r in x])
     if (not self.is_update
         and (self.plan_version is None
              or rate_ids(rate_instances).symmetric_difference(rate_ids(self.plan_version.product_rates.all())))):
         self.is_update = True
     return original_data
开发者ID:dszafranek,项目名称:commcare-hq,代码行数:22,代码来源:forms.py

示例15: clean

# 需要导入模块: from django.forms.util import ErrorList [as 别名]
# 或者: from django.forms.util.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()

            # Currently no file is uploaded so we continue validation.
            # If a file is already updated is and you haven't

#            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([])
#            else:
#                raise ValidationError(self.error_messages['invalid'])

        if value[0]:
            try:
                field_value = value[0]
            except IndexError:
                field_value = None
            if self.required and field_value in validators.EMPTY_VALUES:
                raise ValidationError(self.error_messages['required'])
            try:
                clean_data.append(self.fields[0].clean(field_value))
            except ValidationError, 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.extend([None for i in range(6)])
开发者ID:lewistaylor,项目名称:djcrop,代码行数:42,代码来源:fields.py


注:本文中的django.forms.util.ErrorList.extend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。