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


Python validators.MinValueValidator方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def __init__(self, *args, **kwargs):
        try:
            self.model_field = kwargs.pop('model_field')
        except KeyError:
            raise ValueError("ModelField requires 'model_field' kwarg")

        self.min_length = kwargs.pop('min_length',
                                     getattr(self.model_field, 'min_length', None))
        self.max_length = kwargs.pop('max_length',
                                     getattr(self.model_field, 'max_length', None))
        self.min_value = kwargs.pop('min_value',
                                    getattr(self.model_field, 'min_value', None))
        self.max_value = kwargs.pop('max_value',
                                    getattr(self.model_field, 'max_value', None))

        super(ModelField, self).__init__(*args, **kwargs)

        if self.min_length is not None:
            self.validators.append(validators.MinLengthValidator(self.min_length))
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
        if self.min_value is not None:
            self.validators.append(validators.MinValueValidator(self.min_value))
        if self.max_value is not None:
            self.validators.append(validators.MaxValueValidator(self.max_value)) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:27,代码来源:fields.py

示例2: validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        validators_ = super().validators
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if min_value is not None:
            for validator in validators_:
                if isinstance(validator, validators.MinValueValidator) and validator.limit_value >= min_value:
                    break
            else:
                validators_.append(validators.MinValueValidator(min_value))
        if max_value is not None:
            for validator in validators_:
                if isinstance(validator, validators.MaxValueValidator) and validator.limit_value <= max_value:
                    break
            else:
                validators_.append(validators.MaxValueValidator(max_value))
        return validators_ 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:21,代码来源:__init__.py

示例3: validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        validators_ = super(IntegerField, self).validators
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if min_value is not None:
            for validator in validators_:
                if isinstance(validator, validators.MinValueValidator) and validator.limit_value >= min_value:
                    break
            else:
                validators_.append(validators.MinValueValidator(min_value))
        if max_value is not None:
            for validator in validators_:
                if isinstance(validator, validators.MaxValueValidator) and validator.limit_value <= max_value:
                    break
            else:
                validators_.append(validators.MaxValueValidator(max_value))
        return validators_ 
开发者ID:Yeah-Kun,项目名称:python,代码行数:21,代码来源:__init__.py

示例4: __init__

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def __init__(self, verbose_name=None, name=None, min_value=None, max_value=None, *args, **kwargs):
        self.min_value = min_value
        self.max_value = max_value

        validators = kwargs.pop('validators', [])
        if min_value:
            validators.append(MinValueValidator(min_value))
        if max_value:
            validators.append(MaxValueValidator(max_value))

        return super(IntegerRangeField, self).__init__(
            verbose_name=verbose_name,
            name=name,
            validators=validators,
            *args,
            **kwargs
        ) 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:19,代码来源:fields.py

示例5: __init__

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def __init__(self, request, instance, *args, **kwargs):
        super(SnapshotDefineSerializer, self).__init__(request, instance, *args, **kwargs)

        if not kwargs.get('many', False):
            dc_settings = request.dc.settings

            # Limit maximum number of snapshots - Issue #chili-447
            if dc_settings.VMS_VM_SNAPSHOT_LIMIT_AUTO is None:
                min_count, max_count = RETENTION_MIN, RETENTION_MAX
            else:
                min_count, max_count = 1, int(dc_settings.VMS_VM_SNAPSHOT_LIMIT_AUTO)

            self.fields['retention'].validators.append(validators.MinValueValidator(min_count))
            self.fields['retention'].validators.append(validators.MaxValueValidator(max_count))

            if instance.vm.is_kvm():
                self._update_fields_ = list(self._update_fields_)
                self._update_fields_.append('fsfreeze') 
开发者ID:erigones,项目名称:esdc-ce,代码行数:20,代码来源:serializers.py

示例6: clean

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def clean(self, value):
        value = super().clean(value)
        if value is not None:
            # Exit early if this is percentage value.
            if is_percentage(value):
                return value
            else:
                value = machine_readable_bytes(value)

        # Run validation again, but with the min and max validators. This is
        # because the value has now been converted to an integer.
        self.validators = []
        if self.min_value is not None:
            self.validators.append(MinValueValidator(self.min_value))
        if self.max_value is not None:
            self.validators.append(MaxValueValidator(self.max_value))
        self.run_validators(value)
        return value 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:fields_storage.py

示例7: test_sets_up_fields_based_on_pod_no_max_cpu_speed

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def test_sets_up_fields_based_on_pod_no_max_cpu_speed(self):
        request = MagicMock()
        pod = make_pod_with_hints()
        pod.hints.cpu_speed = 0
        pod.save()
        form = ComposeMachineForm(request=request, pod=pod)
        self.assertThat(
            form.fields["cpu_speed"],
            MatchesStructure(
                required=Equals(False),
                validators=MatchesSetwise(
                    MatchesAll(
                        IsInstance(MinValueValidator),
                        MatchesStructure(limit_value=Equals(300)),
                    )
                ),
            ),
        ) 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:test_pods.py

示例8: initialize

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def initialize(self, grade_source):
        self.fields['grade'].validators.extend([
            MinValueValidator(grade_source.lower_bound),
            MaxValueValidator(grade_source.upper_bound),
        ])
        self.fields['grade'].widget.attrs['size'] = 5 
开发者ID:sfu-fas,项目名称:coursys,代码行数:8,代码来源:forms.py

示例9: __init__

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def __init__(self, max_value=None, min_value=None, *args, **kwargs):
        self.max_value, self.min_value = max_value, min_value
        if kwargs.get('localize') and self.widget == NumberInput:
            # Localized number input is not well supported on most browsers
            kwargs.setdefault('widget', super(IntegerField, self).widget)
        super(IntegerField, self).__init__(*args, **kwargs)

        if max_value is not None:
            self.validators.append(validators.MaxValueValidator(max_value))
        if min_value is not None:
            self.validators.append(validators.MinValueValidator(min_value)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:fields.py

示例10: validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        range_validators = []
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if min_value is not None:
            range_validators.append(validators.MinValueValidator(min_value))
        if max_value is not None:
            range_validators.append(validators.MaxValueValidator(max_value))
        return super(IntegerField, self).validators + range_validators 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:__init__.py

示例11: test_with_validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def test_with_validators(self):
        field = encrypt(
            models.IntegerField(validators=[validators.MinValueValidator(1)]))
        field.clean(1, None)
        with self.assertRaises(exceptions.ValidationError) as cm:
            field.clean(0, None)
        self.assertEqual('Ensure this value is greater than or equal to 1.',
                         cm.exception.messages[0]) 
开发者ID:georgemarshall,项目名称:django-cryptography,代码行数:10,代码来源:test_encrypted.py

示例12: get_fields

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def get_fields(self):
        fields = super().get_fields()
        fields['subname'].validators.append(ReadOnlyOnUpdateValidator())
        fields['type'].validators.append(ReadOnlyOnUpdateValidator())
        fields['ttl'].validators.append(MinValueValidator(limit_value=self.domain.minimum_ttl))
        return fields 
开发者ID:desec-io,项目名称:desec-stack,代码行数:8,代码来源:serializers.py

示例13: __init__

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def __init__(self, *, max_value=None, min_value=None, **kwargs):
        self.max_value, self.min_value = max_value, min_value
        if kwargs.get('localize') and self.widget == NumberInput:
            # Localized number input is not well supported on most browsers
            kwargs.setdefault('widget', super().widget)
        super().__init__(**kwargs)

        if max_value is not None:
            self.validators.append(validators.MaxValueValidator(max_value))
        if min_value is not None:
            self.validators.append(validators.MinValueValidator(min_value)) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:fields.py

示例14: validators

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        validators_ = super().validators
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if (min_value is not None and not
            any(isinstance(validator, validators.MinValueValidator) and
                validator.limit_value >= min_value for validator in validators_)):
            validators_.append(validators.MinValueValidator(min_value))
        if (max_value is not None and not
            any(isinstance(validator, validators.MaxValueValidator) and
                validator.limit_value <= max_value for validator in validators_)):
            validators_.append(validators.MaxValueValidator(max_value))
        return validators_ 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:17,代码来源:__init__.py

示例15: validate

# 需要导入模块: from django.core import validators [as 别名]
# 或者: from django.core.validators import MinValueValidator [as 别名]
def validate(self, data):
        errors = {}
        request = self.context['request']
        card = None
        if request.method == 'POST':
            try:
                data['card'] = models.Card.objects.get(pk=request.POST['card'])
                card = data['card']
            except (ObjectDoesNotExist, KeyError):
                if 'card' not in request.POST:
                    errors['card'] = 'This field is required'
                else:
                    errors['card'] = 'Invalid id'
            try:
                data['owner_account'] = models.Account.objects.get(pk=request.POST['owner_account'], owner=request.user)
            except (ObjectDoesNotExist, KeyError):
                if 'owner_account' not in request.POST:
                    errors['owner_account'] = 'This field is required'
                else:
                    errors['owner_account'] = 'This account does\'t exist or isn\'t yours'
        else:
            card = self.instance.card
        # Check for skill slots
        if 'skill_slots' in data and card:
            for validator in [MinValueValidator(card.min_skill_slot), MaxValueValidator(card.max_skill_slot)]:
                try:
                    validator(data['skill_slots'])
                except DjangoCoreValidationError as e:
                    errors['skill_slots'] = e.messages
        elif card:
            data['skill_slots'] = card.min_skill_slot
        if errors:
            raise serializers.ValidationError(errors)
        return data 
开发者ID:MagiCircles,项目名称:SchoolIdolAPI,代码行数:36,代码来源:serializers.py


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