Python django.core.validators 模块,MaxLengthValidator() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.core.validators.MaxLengthValidator()

项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def set_chars(instance, field, max_length=255):
    """ CharField """
    possibles = []
    possibles.extend(get_field_choices(field))
    if possibles:
        setattr(instance, field.name, random.choice(possibles))
        return

    max_length = min(max_length, field.max_length or 16 * 1024)
    for validator in field.validators:
        if isinstance(validator, MaxLengthValidator):
            max_length = min(max_length, validator.limit_value)

    value = generate_lorem_ipsum(1, min_len=1, max_len=max(5, max_length // 8), html=False)
    value = Truncator(value).chars(max_length, html=False)
    setattr(instance, field.name, value)
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
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))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        self.empty_value = empty_value
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:django    作者:alexsukhrin    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        self.empty_value = empty_value
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def set_text(instance, field, paragraphs=1, html=False):
    """ TextField """
    max_len = field.max_length or 16 * 1024
    for validator in field.validators:
        if isinstance(validator, MaxLengthValidator):
            max_len = min(max_len, validator.limit_value)

    value = generate_lorem_ipsum(paragraphs, html=html)
    value = Truncator(value).chars(max_len, html=html)
    setattr(instance, field.name, value)
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def set_url(instance, field):
    """ URLField """
    possibles = []
    possibles.extend(get_field_choices(field))
    if possibles:
        setattr(instance, field.name, random.choice(possibles))
        return

    max_len = field.max_length
    for validator in field.validators:
        if isinstance(validator, MaxLengthValidator):
            max_len = min(max_len, validator.limit_value)

    value = 'http://google.com/%s/' % generate_random_string(5, 10)
    setattr(instance, field.name, value)
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, allow_none=False, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        self.allow_none = allow_none
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(min_length))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(max_length))
项目:ims    作者:ims-team    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        self.empty_value = empty_value
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:lifesoundtrack    作者:MTG    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:django-bitmask-field    作者:renskiy    | 项目源码 | 文件源码
def __validators(self):
        for validator in self.validators:
            if isinstance(validator, validators.MaxLengthValidator):
                max_value = 2 ** (validator.limit_value * 8)
                yield validators.MaxValueValidator(max_value)
            else:
                yield validator
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        self.empty_value = empty_value
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:CSCE482-WordcloudPlus    作者:ggaytan00    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:tissuelab    作者:VirtualPlants    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:producthunt    作者:davidgengler    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:django-rtc    作者:scifiswapnil    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        self.empty_value = empty_value
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, empty_value='', *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        self.empty_value = empty_value
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:DjangoZeroToHero    作者:RayParra    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:Roboism    作者:markroxor    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, strip=True, *args, **kwargs):
        self.max_length = max_length
        self.min_length = min_length
        self.strip = strip
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:bring_the_idea    作者:GrigoriyMikhalkin    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.min_length = 6
        self.max_length = 32
        kwargs["max_length"] = kwargs.get("max_length", self.max_length)

        super().__init__(*args, **kwargs)
        self.validators.append(MinLengthValidator(self.min_length))
        self.validators.append(MaxLengthValidator(self.max_length))
项目:bring_the_idea    作者:GrigoriyMikhalkin    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        self.min_length = 6
        self.max_length = 33
        kwargs["max_length"] = kwargs.get("max_length", self.max_length)

        super().__init__(*args, **kwargs)
        self.validators.append(MinLengthValidator(self.min_length))
        self.validators.append(MaxLengthValidator(self.max_length))
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def __init__(self, max_length=None, min_length=None, *args, **kwargs):
        self.max_length, self.min_length = max_length, min_length
        super(CharField, self).__init__(*args, **kwargs)
        if min_length is not None:
            self.validators.append(validators.MinLengthValidator(int(min_length)))
        if max_length is not None:
            self.validators.append(validators.MaxLengthValidator(int(max_length)))
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        super(CharField, self).__init__(*args, **kwargs)
        self.validators.append(validators.MaxLengthValidator(self.max_length))
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs['editable'] = False
        super(BinaryField, self).__init__(*args, **kwargs)
        if self.max_length is not None:
            self.validators.append(validators.MaxLengthValidator(self.max_length))