How to use the wtforms.validators.Length function in WTForms

To help you get started, we’ve selected a few WTForms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zkqiang / job-web-demo / job_web / forms.py View on Github external
details = CKEditorField('企业详情', validators=[Length(0, 1000, message='最多1000个字符')])
    submit = SubmitField('提交')

    def update_detail(self, company):
        self.populate_obj(company)
        filename = uploaded_logo.save(self.logo.data, name=random_name())
        logo_url = uploaded_logo.url(filename)
        company.logo = logo_url
        db.session.add(company)
        db.session.commit()
        return logo_url


class JobForm(FlaskForm):

    name = StringField('职位名称', validators=[DataRequired(message='请填写内容'), Length(4, 64)])
    salary_min = IntegerField('最低薪水(单位:千元)', validators=[DataRequired(message='请填写整数')])
    salary_max = IntegerField('最高薪水(单位:千元)', validators=[DataRequired(message='请填写整数')])
    city = StringField('工作城市', validators=[DataRequired(message='请填写内容'),
                                           Length(0, 16, message='最多16个字符')])
    tags = StringField('职位标签(用逗号区隔)', validators=[Length(0, 64)])
    exp = SelectField('工作年限', choices=[(i, i) for i in EXP])
    education = SelectField('学历要求', choices=[(i, i) for i in EDUCATION])
    treatment = CKEditorField('职位待遇', validators=[Length(0, 256, message='最多256个字符')])
    description = CKEditorField('职位描述', validators=[DataRequired(message='请填写内容')])
    is_enable = SelectField('发布', choices=[(True, '立即发布'), (False, '暂不发布')], coerce=bool)
    submit = SubmitField('提交')

    def validate_salary_min(self, field):
        if field.data <= 0 or field.data > 100:
            raise ValidationError('须填写0~100之间的整数')
        if self.salary_max.data and field.data >= self.salary_max.data:
github CityOfNewYork / NYCOpenRecords / public_records_portal / forms.py View on Github external
class OfflineRequestForm(Form):
    request_category = SelectField(u'Category*', choices=categories,
                                   validators=[
                                       DataRequired(
                                           'The request category '
                                           'is required')])
    request_agency = SelectField(u'Agency*', choices=agencies,
                                 validators=[
                                     DataRequired('Please select an agency')],
                                 default='')
    request_summary = TextAreaField(u'Summary*',
                                    validators=[
                                        DataRequired(
                                            'You must enter a '
                                            'summary of your request'),
                                        Length(1, 250,
                                               'Your request summary '
                                               'must be less '
                                               'than 250 characters')])
    request_text = TextAreaField(u'Detailed Description*', validators=[
        Length(1, 5000,
               'The detailed description of this request must be less than '
               '5000 characters')])
    request_attachment_description = TextAreaField(u'Description of Attachment', validators=[Length(1,5000,'less than 5000 characters')])
    request_attachment = FileField(u'Upload attachment')
    request_format = SelectField(u'Format Received*', choices=formats,
                                 validators=[
                                     DataRequired(
                                         'You must enter the format in '
                                         'which the request was received')],
                                 default='')
    request_date = DateField(u'Request Date*', format='%m/%d/%Y',
github magic-akari / BookLibrary / app / main / auth / forms.py View on Github external
password = PasswordField(u'密码',
                             validators=[DataRequired(message=u"该项忘了填写了!"), EqualTo('password2', message=u'密码必须匹配'),
                                         Length(6, 32)])
    password2 = PasswordField(u'再次确认密码', validators=[DataRequired(message=u"该项忘了填写了!")])
    submit = SubmitField(u'注册')

    def validate_email(self, filed):
        if User.query.filter(db.func.lower(User.email) == db.func.lower(filed.data)).first():
            raise ValidationError(u'该 Email 已经被注册了')


class ChangePasswordForm(FlaskForm):
    old_password = PasswordField(u'旧密码', validators=[DataRequired(message=u"该项忘了填写了!")])
    new_password = PasswordField(u'新密码', validators=[DataRequired(message=u"该项忘了填写了!"),
                                                     EqualTo('confirm_password', message=u'密码必须匹配'),
                                                     Length(6, 32)])
    confirm_password = PasswordField(u'确认新密码', validators=[DataRequired(message=u"该项忘了填写了!")])
    submit = SubmitField(u"保存密码")

    def validate_old_password(self, filed):
        from flask_login import current_user
        if not current_user.verify_password(filed.data):
            raise ValidationError(u'原密码错误')
github arrti / shadowsocks-admin / ss_admin / forms / admin.py View on Github external
# author arrti

from wtforms import validators, StringField
from flask.ext.wtf import Form


class login(Form):
    email = StringField('email', validators=[
        validators.DataRequired(message='email is required'),
        validators.Length(min=4, message='email is too short'),
        validators.Email(message='email is invalid')
    ])

    password = StringField('password', validators=[
        validators.DataRequired(message='password is required'),
        validators.Length(min=6, max=32, message='password is required 6~32 characters')
    ])

    vcode = StringField('vcode', validators=[
        validators.DataRequired(message='verification code is required')
    ])
github eevee / floof / floof / views / controls / certificates.py View on Github external
class BrowserCertificateForm(CertificateForm):
    pubkey = KeygenField(u'Public Key')
    generate_browser = wtforms.fields.SubmitField(u'Generate In Browser')

    def validate_pubkey(form, field):
        if not field.data and form.generate_browser.data:
            raise wtforms.ValidationError('It looks like your browser '
                    'doesn\'t support this method.  Try "Generate '
                    'Certificate on Server".')

class ServerCertificateForm(CertificateForm):
    name = wtforms.fields.TextField(u'Cert Friendly Name', [
            wtforms.validators.Length(max=64),
            ])
    passphrase = wtforms.fields.PasswordField(u'Cert Passphrase', [
            wtforms.validators.Length(max=64),
            ])
    generate_server = wtforms.fields.SubmitField(u'Generate On Server')

class RevokeCertificateForm(FloofForm):
    ok = wtforms.fields.SubmitField(u'Revoke Certificate')
    cancel = wtforms.fields.SubmitField(u'Cancel')


@view_config(
    route_name='controls.certs',
    permission='auth.certificates',
    request_method='GET',
    renderer='account/controls/certificates.mako')
def certificates(context, request):
    return dict()
github devopsloft / devopsloft / register.py View on Github external
from wtforms import Form, BooleanField, StringField, validators
# from flask import request


class RegistrationForm(Form):
    name = StringField('Private Name', [validators.Length(min=2, max=25)])
    surename = StringField('Sure Name', [validators.Length(min=2, max=25)])
    email = StringField('Email Address', [validators.Length(min=6, max=35)])
    ismaster = BooleanField('Are you a DevOps Master?',
                            [validators.DataRequired()])
github TwilioDevEd / appointment-reminders-flask / forms / new_appointment.py View on Github external
from wtforms import StringField, DateTimeField, SelectField
from wtforms.validators import DataRequired, Length
from pytz import common_timezones


def _timezones():
    return [(tz, tz) for tz in common_timezones][::-1]


appointment_times = [(t, t + " minutes") for t in ['15', '30', '45', '60']]


class NewAppointmentForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])
    phone_number = StringField('Phone number', validators=[
                               DataRequired(), Length(min=6)])
    delta = SelectField('Notification time',
                        choices=appointment_times, validators=[DataRequired()])
    time = DateTimeField('Appointment time', validators=[
                         DataRequired()], format="%m-%d-%Y %I:%M%p")
    timezone = SelectField(
        'Time zone', choices=_timezones(), validators=[DataRequired()])
github luoyun / LuoYunCloud / lyweb / app / myun / appliance / forms.py View on Github external
from yweb.forms import Form
from wtforms import BooleanField, TextField, \
    validators, DateTimeField, TextAreaField, IntegerField, \
    PasswordField, SelectMultipleField, FileField, SelectField

from wtforms.validators import ValidationError


from app.appliance.models import OSType

_new_OSType = [(str(x), y) for x, y in OSType]

class ApplianceBaseinfoForm(Form):

    name = TextField( _('Name'), [validators.Length(min=2, max=64)] )
    os = SelectField( _('OS'), choices=_new_OSType )
    summary = TextField( _('Summary') )
    catalog = SelectField( _('Catalog') )
    logo = FileField( _('Logo') )
    description = TextAreaField( _('Description') )