コード例 #1
0
class AddDevice(Form):
    mac = StringField('mac',
                      validators=[
                          validators.DataRequired(),
                          validators.MacAddress(),
                          validators.NoneOf(
                              ['00:00:00:00:00:00', 'FF:FF:FF:FF:FF:FF'],
                              message='Mac must be valid.')
                      ])
コード例 #2
0
class RegForm(Form):
    u = date.today()
    d = timedelta(14)
    t1 = u + timedelta(7)
    t2 = u + timedelta(14)
    t3 = u + timedelta(21)
    mac_address = StringField('Mac Address', [validators.DataRequired(), validators.MacAddress()])
    #name_last = StringField('Last Name', [validators.DataRequired()])
    date_expired = SelectField('Choose Expiration date', choices=[(str(t1), str(t1)), (str(t2), str(t2)), (str(t3), str(t3))])
    email = StringField('Email Address', [validators.DataRequired(), validators.Email(), validators.Length(min=6, max=35)])
    
    submit = SubmitField('Submit')
コード例 #3
0
 def conv_PGMacaddr(self, field_args, **extra):
     field_args.setdefault('label', 'MAC Address')
     field_args['validators'].append(validators.MacAddress())
     return f.TextField(**field_args)
コード例 #4
0
 def conv_PGMacaddr(self, column, field_args, **extra):
     self._nullable_required(column=column, field_args=field_args, **extra)
     field_args.setdefault('label', 'MAC Address')
     field_args['validators'].append(validators.MacAddress())
     return wtforms_fields.StringField(**field_args)
コード例 #5
0
ファイル: orm.py プロジェクト: aitoehigie/britecore_flask
 def conv_PGMacaddr(self, field_args, **extra):
     field_args.setdefault("label", "MAC Address")
     field_args["validators"].append(validators.MacAddress())
     return f.TextField(**field_args)
コード例 #6
0
class ExampleForm(FlaskForm):
    def make_all_required(self):
        # YairEO requires us to set everything to Required
        # see: https://github.com/yairEO/validator/issues/63
        for field in self:
            field.validators += (validators.DataRequired(), )

    def add_parsley_listeners(self):
        for field in self:
            if field.render_kw is None:
                field.render_kw = {'data-parsley-trigger': 'focusout'}
            else:
                field.render_kw.update({'data-parsley-trigger': 'focusout'})

    def tag_number_fields(self):
        for field in [self.num_range, self.num_range_2]:
            if field.render_kw is None:
                field.render_kw = {'type': 'number'}
            else:
                field.render_kw.update({'type': 'number'})

    name = StringField('Name (required)',
                       validators=[validators.DataRequired()])
    email = StringField('E-mail address', validators=[validators.Email()])
    date = StringField('Date in yyyy-mm-dd format',
                       validators=[validators.Regexp(r'\d{4}-\d{2}-\d{2}')])
    nameCheck = StringField('Equal to the name field',
                            validators=[validators.EqualTo('name')])
    ipv4 = StringField(
        'Valid IPv4 address',
        validators=[
            validators.DataRequired(message='This is a custom error message.'),
            validators.IPAddress(ipv4=True, ipv6=False),
        ])
    ipv6 = StringField(
        'Valid IPv6 address',
        validators=[
            validators.DataRequired(message='This is a custom error message.'),
            validators.IPAddress(
                ipv4=False,
                ipv6=True,
                message='This is another custom error message.'),
        ])
    ipv46 = StringField(
        'Valid IPv4 or IPv6 address',
        validators=[validators.IPAddress(ipv4=True, ipv6=True)])
    length_range = StringField('3-8 chars long string',
                               validators=[validators.Length(3, 8)])
    length_range_2 = StringField('min. 3 chars long string',
                                 validators=[validators.Length(min=3)])
    mac = StringField('MAC address', validators=[validators.MacAddress()])

    num_range = IntegerField(
        'Number between 3 and 8',
        validators=[validators.DataRequired(),
                    validators.NumberRange(3, 8)])
    num_range_2 = IntegerField(
        'Number above 2',
        validators=[validators.DataRequired(),
                    validators.NumberRange(min=3)])

    url = StringField('Valid URL', validators=[validators.URL()])
    uuid = StringField('UUID', validators=[validators.UUID()])

    anyof = StringField('Strings alice or [bob]',
                        validators=[validators.AnyOf(['alice', '[bob]'])])
    noneof = StringField('Strings NOT alice or [bob]',
                         validators=[validators.NoneOf(['alice', '[bob]'])])

    optional = StringField(
        'alice or nothing',
        validators=[validators.Optional(),
                    validators.AnyOf(['alice'])])
コード例 #7
0
ファイル: Dashboard.py プロジェクト: Bali189/dashboard
class ReusableForm(Form):
  mac_addr = (
    TextField('MAC Address:', validators=[validators.MacAddress(message=None)])
  )
コード例 #8
0
ファイル: sample.py プロジェクト: glebofff/wtforms-parsleyjs
class ParsleyTestForm(Form):
    email = wtformsparsleyjs.StringField(
        label='E-Mail Address',
        validators=[
            validators.Email(message='Sorrry, not a valid email address.')
        ],
        default='*****@*****.**')

    ip_address = wtformsparsleyjs.StringField(
        label='IP4 Address',
        validators=[
            validators.IPAddress(message='Sorry, not a valid IP4 Address.')
        ],
        default='127.0.0.1')

    uuid = wtformsparsleyjs.StringField(
        label='UUID',
        validators=[validators.UUID(message='Sorry, not a valid UUID.')],
        default='863b5570-ee85-4099-ba1d-33018282cd00')

    mac_address = wtformsparsleyjs.StringField(
        label='Mac Address',
        validators=[
            validators.MacAddress(message='Sorry, not a valid mac address.')
        ],
        default='10:B0:46:8C:80:48')

    string_length = wtformsparsleyjs.StringField(
        label='Length of String (5 to 10)',
        validators=[
            validators.Length(
                message='Length should be between 5 and 10 characters.',
                min=5,
                max=10)
        ],
        default='Hello!')

    number_range = wtformsparsleyjs.IntegerField(
        label='Number Range (5 to 10)',
        validators=[
            validators.NumberRange(message='Range should be between 5 and 10.',
                                   min=5,
                                   max=10)
        ],
        default=7)

    required_text = wtformsparsleyjs.StringField(
        label='Required Field',
        validators=[
            validators.DataRequired(message='Sorry, this is a required field.')
        ],
        default='Mandatory text')

    required_select = wtformsparsleyjs.SelectField(
        label='Required Select',
        validators=[
            validators.DataRequired(
                message='Sorry, you have to make a choice.')
        ],
        choices=[('', 'Please select an option'), ('cpp', 'C++'),
                 ('py', 'Python'), ('text', 'Plain Text')],
        default='py')

    required_checkbox = wtformsparsleyjs.BooleanField(
        label='Required Checkbox',
        validators=[
            validators.DataRequired(message='Sorry, you need to accept this.')
        ],
        default=True)

    regexp = wtformsparsleyjs.StringField(
        label='Regex-Matched Hex Color-Code',
        validators=[
            validators.Regexp(message='Not a proper color code, sorry.',
                              regex=r'^#[A-Fa-f0-9]{6}$')
        ],
        default='#7D384F')

    url = wtformsparsleyjs.StringField(
        label='URL Field',
        validators=[validators.URL(message='Sorry, this is not a valid URL,')],
        default='http://example.com/parsley')

    anyof = wtformsparsleyjs.StringField(
        'Car, Bike or Plane?',
        validators=[
            validators.AnyOf(
                message='Sorry, you can only choose from car, bike and plane',
                values=['car', 'bike', 'plane'])
        ],
        default='car')

    date_of_birth = wtformsparsleyjs.DateField(
        label="Date of birth in the format DD-MM-YYYY",
        format="%d-%m-%Y",
        validators=[
            validators.InputRequired(message="Sorry this input is required.")
        ],
        default=datetime.datetime.today().date())

    date_time = wtformsparsleyjs.DateTimeField(
        label="Date and time in the format DD/MM/YYYY HH:MM",
        format="%d/%m/%Y %H:%M",
        validators=[
            validators.InputRequired(message="Sorry this input is required.")
        ],
        default=datetime.datetime.today())

    length = wtformsparsleyjs.DecimalField(
        label="Exact length, as a decimal",
        validators=[
            validators.InputRequired(message="Sorry this input is required.")
        ],
        default=4.20)

    txt_file = wtformsparsleyjs.FileField(
        label="Optional file field, of .txt format",
        validators=[
            validators.Regexp(r"^.+\.txt$", message="Must be a *.txt file"),
            validators.Optional()
        ])

    float_field = wtformsparsleyjs.FloatField(
        label="A float value",
        validators=[
            validators.InputRequired(message="Sorry this input is required.")
        ],
        default=4.20)

    best_thing_ever = wtformsparsleyjs.RadioField(
        label="Is this the best thing ever?",
        choices=[("y", "Yes"), ("n", "No")],
        validators=[
            validators.InputRequired(message="We need and answer please.")
        ],
        default="y")

    colour = wtformsparsleyjs.SelectField(
        label="Select your favourite colour.",
        choices=[("red", "Red"), ("blue", "Blue"), ("green", "Green")],
        validators=[
            validators.InputRequired(message="Sorry this input is required.")
        ])

    hobbies = wtformsparsleyjs.SelectMultipleField(
        label="Select your hobbies: ",
        choices=[("cooking", "Cooking"), ("coding", "Coding"),
                 ("reading", "Reading"), ("fishing", "Fishing"),
                 ("sewing", "Sewing")],
        validators=[validators.Optional()])

    name = wtformsparsleyjs.StringField(
        label="Whom would you have me welease?",
        validators=[
            validators.NoneOf(["Roger", "Roderick", "Woger", "Woderick"],
                              message="Ah. We have no Woger and no Woderick")
        ],
        default="Brian")

    hidden = wtformsparsleyjs.HiddenField(
        label="Hidden value",
        validators=[
            validators.NumberRange(min=5, message="Must be greater than 5")
        ],
        default=6)

    # No default values for passwords, becuase the aren't rendered as a safety
    # feature.
    secret = wtformsparsleyjs.PasswordField(
        label="Enter your secret:",
        validators=[
            validators.InputRequired(message="Sorry this input is required.")
        ],
    )

    same_secret = wtformsparsleyjs.PasswordField(
        label="Enter your secret again: ",
        validators=[
            validators.EqualTo(fieldname="secret",
                               message="Secrets do not match.")
        ],
    )

    life_story = wtformsparsleyjs.TextAreaField(
        label="Tell us your life story...",
        validators=[
            validators.Length(
                min=50,
                message="C'mon that's not long enough to be a life story")
        ],
        default="This is my life story, it has to be at least 50 characters.")