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


Python validators.EMPTY_VALUES属性代码示例

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


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

示例1: run_validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def run_validators(self, value):
        if value in validators.EMPTY_VALUES:
            return
        errors = []
        for v in self.validators:
            try:
                v(value)
            except ValidationError as e:
                if hasattr(e, 'code') and e.code in self.error_messages:
                    message = self.error_messages[e.code]
                    if e.params:
                        message = message % e.params
                    errors.append(message)
                else:
                    errors.extend(e.messages)
        if errors:
            raise ValidationError(errors) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:19,代码来源:fields.py

示例2: to_python

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def to_python(self, value):
        """
        Validates that the input can be converted to a datetime. Returns a
        Python datetime.datetime object.
        """
        if value in validators.EMPTY_VALUES:
            return None
        if isinstance(value, datetime.datetime):
            return from_current_timezone(value)
        if isinstance(value, datetime.date):
            result = datetime.datetime(value.year, value.month, value.day)
            return from_current_timezone(result)
        if isinstance(value, list):
            # Input comes from a SplitDateTimeWidget, for example. So, it's two
            # components: date and time.
            if len(value) != 2:
                raise ValidationError(self.error_messages['invalid'])
            if value[0] in validators.EMPTY_VALUES and value[1] in validators.EMPTY_VALUES:
                return None
            value = '%s %s' % tuple(value)
        result = super(DateTimeField, self).to_python(value)
        return from_current_timezone(result) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:fields.py

示例3: run_validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def run_validators(self, value):
        if value in validators.EMPTY_VALUES:
            return

        errors = []
        for v in self.validators:
            try:
                v(value)
            except exceptions.ValidationError as e:
                if hasattr(e, 'code') and e.code in self.error_messages:
                    message = self.error_messages[e.code]
                    if e.params:
                        message = message % e.params
                    errors.append(message)
                else:
                    errors.extend(e.messages)
        if errors:
            raise exceptions.ValidationError(errors) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:20,代码来源:__init__.py

示例4: run_validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def run_validators(self, value):
        if value in validators.EMPTY_VALUES:
            return

        errors = []

        for v in self.validators:
            try:
                v(value)
            except ValidationError as e:
                if hasattr(e, 'code') and e.code in self.error_messages:
                    message = self.error_messages[e.code]
                    if e.params:
                        message = message % e.params
                    errors.append(message)
                else:
                    errors.extend(e.messages)
        if errors:
            raise ValidationError(errors) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:21,代码来源:fields.py

示例5: from_native

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def from_native(self, data):
        if data in validators.EMPTY_VALUES:
            return None

        # UploadedFile objects should have name and size attributes.
        try:
            file_name = data.name
            file_size = data.size
        except AttributeError:
            raise ValidationError(self.error_messages['invalid'])

        if self.max_length is not None and len(file_name) > self.max_length:
            error_values = {'max': self.max_length, 'length': len(file_name)}
            raise ValidationError(self.error_messages['max_length'] % error_values)
        if not file_name:
            raise ValidationError(self.error_messages['invalid'])
        if not self.allow_empty_file and not file_size:
            raise ValidationError(self.error_messages['empty'])

        return data 
开发者ID:erigones,项目名称:esdc-ce,代码行数:22,代码来源:fields.py

示例6: clean_global_empty

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def clean_global_empty(self, value):
        """Make sure the value is not empty and is thus suitable to be
        feed to the sub fields' validators."""
        if not value or isinstance(value, (list, tuple)):
            # value is considered empty if it is in
            # validators.EMPTY_VALUES, or if each of the subvalues is
            # None.
            is_empty = value in validators.EMPTY_VALUES or all(
                v is None for v in value
            )
            if is_empty:
                if self.required:
                    raise ValidationError(self.error_messages["required"])
                else:
                    return None
            else:
                return True
        else:
            raise ValidationError(self.error_messages["invalid"]) 
开发者ID:maas,项目名称:maas,代码行数:21,代码来源:config_forms.py

示例7: get_used_media

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def get_used_media():
    """
        Get media which are still used in models
    """

    media = set()

    for field in get_file_fields():
        is_null = {
            '%s__isnull' % field.name: True,
        }
        is_empty = {
            '%s' % field.name: '',
        }

        storage = field.storage

        for value in field.model._base_manager \
                .values_list(field.name, flat=True) \
                .exclude(**is_empty).exclude(**is_null):
            if value not in EMPTY_VALUES:
                media.add(storage.path(value))

    return media 
开发者ID:akolpakov,项目名称:django-unused-media,代码行数:26,代码来源:cleanup.py

示例8: get_check_for_field

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def get_check_for_field(self, field_name, checking_fields=None):
        if checking_fields is None:
            checking_fields = self.get_checking_fields()

        if field_name not in checking_fields:
            raise AttributeError("Field '%s' not checkable" % field_name)

        field = checking_fields.get(field_name)
        check = CheckResult(field=field)

        # custom check method
        if self.has_custom_check_for_field(field_name):
            return getattr(self, 'check_%s' % field_name)(check)

        # default check
        if isinstance(field, PrimaryKeyRelatedField):
            value = getattr(self, field_name).all()
            has_failed = bool(value.count() == 0)
        else:
            value = getattr(self, field_name)
            has_failed = bool(value in EMPTY_VALUES)

        if has_failed:
            check.mark_fail()
        else:
            check.mark_pass()
        return check 
开发者ID:dulacp,项目名称:django-accounting,代码行数:29,代码来源:checks.py

示例9: to_python

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def to_python(self, value):
        if value in validators.EMPTY_VALUES:
            raise ValidationError(self.error_messages['required'])
        try:
            value = int(value)
        except ValueError:
            raise forms.ValidationError("Invalid format")
        try:
            student = Person.objects.get(emplid=value)
        except Person.DoesNotExist:
            raise forms.ValidationError("Could not find student record")
        return student 
开发者ID:sfu-fas,项目名称:coursys,代码行数:14,代码来源:forms.py

示例10: to_python

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def to_python(self, value):
        
        if value in validators.EMPTY_VALUES and self.required:
            raise ValidationError(self.error_messages['required'])
        if '.' in value:
            raise ValidationError('Invalid format. Must be a whole number or a proper fraction')
        
        try:
            value = Fraction(value)
        except ValueError:
            raise ValidationError('Invalid format. Must be a whole number or a proper fraction')
        except ZeroDivisionError:
            raise ValidationError('Denominator of fraction cannot be zero')
        
        return value 
开发者ID:sfu-fas,项目名称:coursys,代码行数:17,代码来源:teaching_equiv_forms.py

示例11: clean

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def clean(self, value):
        super(CAPhoneNumberField, self).clean(value)
        if value in EMPTY_VALUES:
            return ''
        value = re.sub('(\(|\)|\s+)', '', force_text(value))
        m = phone_digits_re.search(value)
        if m:
            return '%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
        raise forms.ValidationError(self.error_messages['invalid']) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:11,代码来源:forms.py

示例12: _set_column_django_attributes

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def _set_column_django_attributes(self, cql_column, name):
        allow_null = (
            (not cql_column.required and
             not cql_column.is_primary_key and
             not cql_column.partition_key) or cql_column.has_default and not cql_column.required
        )
        cql_column.error_messages = self.default_field_error_messages
        cql_column.empty_values = list(validators.EMPTY_VALUES)
        cql_column.db_index = cql_column.index
        cql_column.serialize = True
        cql_column.unique = cql_column.is_primary_key
        cql_column.hidden = False
        cql_column.auto_created = False
        cql_column.help_text = ''
        cql_column.blank = allow_null
        cql_column.null = allow_null
        cql_column.choices = []
        cql_column.flatchoices = []
        cql_column.validators = []
        cql_column.editable = True
        cql_column.concrete = True
        cql_column.many_to_many = False
        cql_column.many_to_one = False
        cql_column.one_to_many = False
        cql_column.one_to_one = False
        cql_column.is_relation = False
        cql_column.remote_field = None
        cql_column.unique_for_date = None
        cql_column.unique_for_month = None
        cql_column.unique_for_year = None
        cql_column.db_column = None
        cql_column.rel = None
        cql_column.attname = name
        cql_column.field = cql_column
        cql_column.model = self.model_inst
        cql_column.name = cql_column.db_field_name
        cql_column.verbose_name = cql_column.db_field_name
        cql_column._verbose_name = cql_column.db_field_name
        cql_column.field.related_query_name = lambda: None 
开发者ID:r4fek,项目名称:django-cassandra-engine,代码行数:41,代码来源:__init__.py

示例13: is_valid_list_int_greater_zero_param

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def is_valid_list_int_greater_zero_param(list_param, required=True):
    """Checks if the parameter list is a valid integer value and greater than zero.

    @param param: Value to be validated.

    @raise ValidationError: If there is validation error in the field
    """
    if required and list_param in validators.EMPTY_VALUES:
        raise ValueError('Field is required.')

    try:
        for param in list_param:

            if param is None and required:
                raise ValueError('Field is required.')

            try:
                param = int(param)

                if param < 1:
                    raise ValueError('Field must be an positive integer.')

            except Exception:
                raise ValueError('Field must be an integer.')

    except Exception:
        raise ValueError('Invalid List Parameter.')

    return True 
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:31,代码来源:__init__.py

示例14: validate

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [as 别名]
def validate(self, value):
        if value in validators.EMPTY_VALUES and self.required:
            raise ValidationError(self.error_messages['required']) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:5,代码来源:fields.py

示例15: clean

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import EMPTY_VALUES [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 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:blackye,项目名称:luscan-devel,代码行数:42,代码来源:fields.py


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