當前位置: 首頁>>代碼示例>>Python>>正文


Python validators.MaxValueValidator方法代碼示例

本文整理匯總了Python中django.core.validators.MaxValueValidator方法的典型用法代碼示例。如果您正苦於以下問題:Python validators.MaxValueValidator方法的具體用法?Python validators.MaxValueValidator怎麽用?Python validators.MaxValueValidator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.validators的用法示例。


在下文中一共展示了validators.MaxValueValidator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: validators

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例2: validators

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例3: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例4: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例5: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例6: clean

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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: formfield

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [as 別名]
def formfield(self, **kwargs):
        defaults = {'min_value': self.min_value, 'max_value':self.max_value}
        defaults.update(kwargs)
        field = super(FileSizeField, self).formfield(**defaults)
        # monkey-patch a better error message
        for v in field.validators:
            if isinstance(v, MaxValueValidator):
                v.message = "We currently limit submissions to %i kB on this system. For larger files, we suggest having students upload the files to their web space and submitting a URL." % (settings.MAX_SUBMISSION_SIZE)
        return field 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:11,代碼來源:base.py

示例8: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例9: validators

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例10: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [as 別名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        user_sshkeys = self.created_by.created_sshkeys.all()
        self.fields["ssh_key"].queryset = user_sshkeys.all()
        self.fields["ssh_key"].help_text = (
            "The SSH key to deploy to the cluster. "
            'See <a href="%s">your keys</a> or '
            '<a href="%s">add a new one</a>.'
            % (reverse("keys-list"), reverse("keys-new"))
        )
        # if the user is not a cluster maintainer, reset the max
        # to the default so they can't create larger clusters
        if not self.created_by.has_perm("clusters.maintain_cluster"):
            max_size = settings.AWS_CONFIG["MAX_CLUSTER_SIZE"]
            self.fields["size"].max_value = max_size
            self.fields["size"].validators.append(
                validators.MaxValueValidator(max_size)
            )
            self.fields["size"].widget.attrs["max"] = max_size
            self.fields["size"].help_text = (
                "Number of workers to use in the cluster, between 1 and %s. "
                "For testing or development 1 is recommended." % max_size
            )

        # if there are fewer options we just show radio select buttons
        if user_sshkeys.count() <= 6:
            self.fields["ssh_key"].widget = forms.RadioSelect(
                choices=self.fields["ssh_key"].choices, attrs={"class": "radioset"}
            ) 
開發者ID:mozilla,項目名稱:telemetry-analysis-service,代碼行數:31,代碼來源:forms.py

示例11: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例12: max_value_current_year

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [as 別名]
def max_value_current_year(value):
    return MaxValueValidator(current_year())(value) 
開發者ID:compserv,項目名稱:hknweb,代碼行數:4,代碼來源:models.py

示例13: validators

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例14: validate

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [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

示例15: __init__

# 需要導入模塊: from django.core import validators [as 別名]
# 或者: from django.core.validators import MaxValueValidator [as 別名]
def __init__(self, max_value=None, min_value=None, *args, **kwargs):
        self.max_value, self.min_value = max_value, min_value
        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:blackye,項目名稱:luscan-devel,代碼行數:10,代碼來源:fields.py


注:本文中的django.core.validators.MaxValueValidator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。