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