當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。