Exemplo n.º 1
0
class PhoneForm(Form):
    phone_number = TelField('Phone number', [
        Required(),
    ])

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        formatted_number = validate_number(self.phone_number.data)
        if not formatted_number:
            self.phone_number.errors.append('Not a valid phone number')
            return False

        self.phone_number.data = formatted_number
        return True
Exemplo n.º 2
0
class ExampleForm(Form):
    field1 = TextField('First Field', description='This is field one.')
    field2 = TextField('Second Field',
                       description='This is field two.',
                       validators=[Required()])
    hidden_field = HiddenField('You cannot see this', description='Nope')
    recaptcha = RecaptchaField('A sample recaptcha field')
    radio_field = RadioField('This is a radio field',
                             choices=[
                                 ('head_radio', 'Head radio'),
                                 ('radio_76fm', "Radio '76 FM"),
                                 ('lips_106', 'Lips 106'),
                                 ('wctr', 'WCTR'),
                             ])

    def validate_hidden_field(form, field):
        raise ValidationError('Always wrong')
Exemplo n.º 3
0
class TechTalkEditForm(Form):
    nickname = TextField('nickname', validators = [Required()])
    about_me = TextAreaField('about_me', validators = [Length(min = 0, max = 140)])

    def __init__(self, original_nickname, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)
        self.original_nickname = original_nickname

    def validate(self):
        if not Form.validate(self):
            return False
        if self.nickname.data == self.original_nickname:
            return True
        user = User.query.filter_by(nickname = self.nickname.data).first()
        if user != None:
            self.nickname.errors.append('This nickname is already in use. Please choose another one.')
            return False
        return True
Exemplo n.º 4
0
class ChangePasswordForm(Form):
    password = PasswordField(
        label=_('New password'),
        validators=[
            Required(message=_('New password is required')),
            Length(
                min=PASSWORD_LEN_MIN,
                max=PASSWORD_LEN_MAX,
                )
            ]
        )
    password_again = PasswordField(
        label=_('New password again'),
        validators=[
            EqualTo('password', message=_("Passwords don't match."))
            ]
        )
    submit = SubmitField(_('Change Password'))
Exemplo n.º 5
0
class SettingsForm(Form):
    username = TextField(
        u'用户名',
        validators=[Required(),
                    Length(min=4, max=32),
                    Regexp(re_username)])
    #nickname = TextField(u'昵称', validators=[Optional(), Length(max=32)])
    city = TextField(u'城市', validators=[Optional(), Length(max=40)])
    province = TextField(u'省份', validators=[Optional(), Length(max=40)])
    birthday = DateField(u'出生年月日',
                         validators=[Optional()],
                         widget=DatePickerWidget(),
                         default=datetime.date(1990, 1, 1))
    blog = TextField(u'博客', validators=[Optional(), URL(), Length(max=100)])
    descp = TextAreaField(u'个人介绍', validators=[Optional(), Length(max=500)])
    signature = TextAreaField(u'签名', validators=[Optional(), Length(max=200)])
    realname = TextField(u'真实姓名', validators=[Optional(), Length(max=80)])
    idcard = TextField(u'身份证', validators=[Optional(), Length(max=32)])
Exemplo n.º 6
0
class BookForm(Form):
    title = TextField(u'title', [Required()])
    authors = SelectMultipleField(u'Authors', coerce=int)
    save = SubmitField(u'Save')

    def __init__(self, *args, **kwargs):
        super(BookForm, self).__init__(*args, **kwargs)
        obj = kwargs.get('obj')
        self.authors.choices = \
            [(author.id, author.name) for author in Author.query.all()]
        if obj:
            selected_authors_ids = [author.id for author in obj.authors]
            self.title.data = obj.title
            self.authors.data = selected_authors_ids

    def populate_obj(self, obj):
        obj.title = self.title.data
        author_ids = self.authors.data
        obj.authors = Author.query.filter(Author.id.in_(author_ids)).all()
Exemplo n.º 7
0
class EditProfileForm(Form):
    username = TextField("Username", validators=[
        Regexp('^[a-zA-Z0-9_.-]+$', 
            message="Username contains invalid characters"), 
        Length(min=2, max=16, 
            message="Username must be between 2 and 16 characters"),
        username_same_or_exists, does_not_have_bad_words])
    
    email = TextField("Email Address", validators=[
        Required(message='Email required'),
        Email(message="Invalid email address")])
    
    password = PasswordField("Change Password", validators=[
        Length(min=4, max=32, 
            message="Username must be between 2 and 16 characters"), 
        EqualTo('password2', message='Passwords must match'),
        Optional()])
    
    password2 = PasswordField("Repeat password", validators=[Optional()])
Exemplo n.º 8
0
class CompletedMatchPlayerForm(Form):
    user_id = SelectField(u'Player',
                          coerce=int,
                          choices=[],
                          validators=[Required()])
    kills = IntegerField(u'Kills', default=0, validators=[NumberRange(min=0)])
    deaths = IntegerField(u'Deaths',
                          default=0,
                          validators=[NumberRange(min=0)])
    off_objs = IntegerField(u'Offensive Objectives',
                            default=0,
                            validators=[NumberRange(min=0)])
    def_objs = IntegerField(u'Defensive Objectives',
                            default=0,
                            validators=[NumberRange(min=0)])
    score = IntegerField(u'Score', default=0)

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('csrf_enabled', False)
        super(CompletedMatchPlayerForm, self).__init__(*args, **kwargs)
Exemplo n.º 9
0
class KioskUserForm(Form):
    username = TextField(validators=[
        Required(message='Username required'),
        Regexp('^[a-zA-Z0-9_.-]+$', 
               message="Username contains invalid characters"), 
        Length(min=2, max=16, 
               message="Username must be between 2 and 16 characters"),
        does_not_have_bad_words
    ])
    
    phonenumber = TextField(validators=[validate_phonenumber, Optional()])
    
    def get_phone(self):
        has_phone = len(self.phonenumber.data) == 10
        return self.phonenumber.data if has_phone else None 
    
    def to_user(self):
        return User(username=self.username.data, 
                    phoneNumber=self.phonenumber.data, 
                    origin="kiosk")
Exemplo n.º 10
0
class EditUserForm(Form):
    next = HiddenField()
    role_code = RadioField(_("Role"),
                           [AnyOf([str(val) for val in USER_ROLE.keys()])],
                           choices=[(str(val), label)
                                    for val, label in USER_ROLE.items()])
    status_code = RadioField(_("Status"),
                             [AnyOf([str(val) for val in USER_STATUS.keys()])],
                             choices=[(str(val), label)
                                      for val, label in USER_STATUS.items()])
    # A demo of datepicker.
    vm_quota = IntegerField(
        _("VM Quota"),
        [Required(), NumberRange(VM_QUOTA_MIN, VM_QUOTA_MAX)])
    created_time = DateField(_('Created time'))
    submit = SubmitField(_('Save'))

    def validate_name(self, field):
        if User.query.filter_by(name=field.data).first() is not None:
            raise ValidationError(_(u'This username is taken'))
Exemplo n.º 11
0
class Deal_Form(Form):
    title = TextField("title",
                      validators=[Required(message='This is required')])
    categories = SelectField(u'Group',
                            choices=[(category.title(), category) for category in cats])
    location = TextField("location",
                         validators=[
                            Length(max=300, message="location can't be longer than 300 characters"),
                            URL(message="Doesn't look like a valid link. Valid links should start with http://")
                         ])
    description = TextAreaField('description',
                                 validators=[
                                    Length(max=5000, message="Description can't be longer than 5000 characters")
                                 ])
    submit = SubmitField("Submit")

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            # Hack - if the self.location.data is "", the URL validator
            # will raise an invalid URL error. But the length validator should
            # raise no errors since "" has length < 300.
            #
            # Therefore, if self.location.data is None, we can assume that
            # there is only 1 location error, and the error is invalid URL.
            # Since we want to allow the user to NOT enter a URL, we will
            # to pop the invalid URL error from self.location.error
            if self.location.data == "":
                self.location.errors.pop()
            if len(self.title.data) > 128:
                num = len(self.title.data) - 128
                message = "This is too long by {num} characters"\
                          .format(num=num)
                self.title.errors.append(message)
            if self.title.errors or self.categories.errors or \
                self.location.errors or self.description.errors:
                return False
        return True
Exemplo n.º 12
0
class Survey4Form(Form):
    computerTime = fields.RadioField('How long have you been using a computer?',
        choices=[('0-2', '0 to 2 Years'), ('3-5', '3 to 5 Years'), ('6-10', '6 to 10 Years'),
            ('mt10', 'More than 10 years')],
        validators=[Required()], default=None)
    pass_random = fields.BooleanField('Randomly generate a password using special software or apps')
    pass_reuse = fields.BooleanField('Reuse a password that is used for another account')
    pass_modify = fields.BooleanField('Modify a password that is used for another account')
    pass_new = fields.BooleanField('Create a new password using a familiar number or a name of a family member')
    pass_substitute = fields.BooleanField('Choose a word and substitute some letters with numbers of symbols (for example @ for a)')
    pass_multiword = fields.BooleanField('Use a pass-phrase consisting of several words')
    pass_phrase = fields.BooleanField('Choose a phrase and use the first letters of each word')
    pass_O = fields.TextAreaField('Other')
    how_regular_file = fields.BooleanField('I store my passwords in a regular file / document on my computer.')
    how_encrypted = fields.BooleanField('I store my passwords in an encrypted computer file')
    how_software = fields.BooleanField('I use password management software to securely store my passwords')
    how_cellphone = fields.BooleanField('I store my passwords on my cellphone / smartphone')
    how_browser = fields.BooleanField('I save my passwords in the browser')
    how_write_down = fields.BooleanField('I write down my password on a piece of paper')
    how_no = fields.BooleanField('No, I do not save my passwords. I remember them.')
    comments = fields.TextAreaField('If you have any additional feedback about passwords or this survey, please enter your comments here.', default=None)
Exemplo n.º 13
0
class EntryAddPackage(Form):
    url = TextField("URL", validators=[Required()])
    type = SelectField("Type",
                       choices=[
                           ("web", entry_package_type_string("web")),
                           ("linux", entry_package_type_string("linux")),
                           ("linux32", entry_package_type_string("linux32")),
                           ("linux64", entry_package_type_string("linux64")),
                           ("windows", entry_package_type_string("windows")),
                           ("windows64",
                            entry_package_type_string("windows64")),
                           ("mac", entry_package_type_string("mac")),
                           ("source", entry_package_type_string("source")),
                           ("git", entry_package_type_string("git")),
                           ("svn", entry_package_type_string("svn")),
                           ("hg", entry_package_type_string("hg")),
                           ("combi", entry_package_type_string("combi")),
                           ("love", entry_package_type_string("love")),
                           ("blender", entry_package_type_string("blender")),
                           ("unknown", entry_package_type_string("unknown"))
                       ])
Exemplo n.º 14
0
class EditForm(Form):
    nickname = TextField('nickname', validators=[Required()])
    age = TextField('age', validators=[])
    gender = TextField('gender', validators=[])
    location = TextField('location', validators=[])
    about_me = TextAreaField('about_me', validators=[Length(min=0, max=140)])
    val_collaboration = TextField('collaboration', validators=[])
    val_competitive_pay = TextField('competitive_pay', validators=[])
    val_empowerment = TextField('empowerment', validators=[])
    val_flex_sched = TextField('flex_sched', validators=[])
    val_advancement_opps = TextField('advancement_opps', validators=[])
    val_honesty = TextField('honesty', validators=[])
    val_innovation = TextField('innovation', validators=[])
    val_medical_benefits = TextField('medical_benefits', validators=[])
    val_mentoring = TextField('mentoring', validators=[])
    val_paid_time_off = TextField('paid_time_off', validators=[])
    val_performance_feedback = TextField('performance_feedback', validators=[])
    val_results_driven = TextField('results_driven', validators=[])
    val_retirement = TextField('retirement', validators=[])
    val_training_development = TextField('training_development', validators=[])
    val_work_from_home = TextField('work_from_home', validators=[])
Exemplo n.º 15
0
class RegisterForm(Form):
#     userobj = mod.User()
#     userobj.name        	 = TextField('Username', validators = [Required(), Length(min=6, max=20)])
#     userobj.email      		 = TextField('Email', validators = [Required(), Length(min=6, max=30)])
#     userobj.password    	 = PasswordField('Password', validators = [Required(), Length(min=6, max=30)])
#     userobj.confirm     	 = PasswordField('Repeat Password', [Required(), EqualTo('password', message='Passwords must match')])
#     userobj.institution 	 = TextField('Institution', validators = [Required(), Length(min=4, max=40)])
#     userobj.security_question= TextField('Security Question', validators = [Required(), Length(min=10, max=40)])
#     userobj.security_answer  = TextField('Security Answer', validators = [Required(), Length(min=4, max=40)])
#     print " comes  RegisterForm"
#     print "name:", userobj.name, "\n","email:",userobj.email
    
    name             = TextField('Username', validators = [Required(), Length(min=6, max=20)])
    email            = TextField('Email', validators = [Required(), Length(min=6, max=30)])
    password         = PasswordField('Password', validators = [Required(), Length(min=6, max=30)])
    confirm          = PasswordField('Repeat Password', [Required(), EqualTo('password', message='Passwords must match')])
    institution      = TextField('Institution', validators = [Required(), Length(min=4, max=40)])
    security_question= TextField('Security Question', validators = [Required(), Length(min=10, max=40)])
    security_answer  = TextField('Security Answer', validators = [Required(), Length(min=4, max=40)])
Exemplo n.º 16
0
class ServiceCouponForm(Form):
    code = TextField("Coupon Code", validators=[Required(), Length(max=10)])
    description = TextField("Description", validators=[Required()])
    discount = TextField("Discount",
                         validators=[Required()
                                     ])  #TODO Custom validator for discount
    per_guest_max_uses = IntegerField("Per Guest Max Uses")
    total_max_uses = IntegerField("Total Max Uses")
    active = BooleanField("Active")
    starts = DateTimeField("Starts On",
                           validators=[Required()],
                           default=datetime.now())
    expires = DateTimeField("Expires On",
                            validators=[Required()],
                            default=datetime.now())
    service_group_id = SelectField("Service Group", validators=[Required()])
Exemplo n.º 17
0
class ProfileForm(Form):
    multipart = True
    next = HiddenField()
    email = EmailField(_(u'Email'), [Required(), Email()])
    vm_quota = IntegerField(_(u'Quota of VirtualMachines'))
    locale_code = RadioField(
        _("Language"),
        [AnyOf([str(val) for val in USER_LOCALE_STRING.keys()])],
        choices=[(str(val), label)
                 for val, label in USER_LOCALE_STRING.items()])

    submit = SubmitField(_(u'Save'))

    def validate_name(form, field):
        user = User.get_by_id(current_user.id)
        if not user.check_name(field.data):
            raise ValidationError(_("Please pick another name."))

    def validate_vm_quota(form, field):
        if (not current_user.is_admin()) and current_user.vm_quota != int(
                field.data):
            raise ValidationError(_("Only admin user can update vm quota."))
Exemplo n.º 18
0
class ContactForm(Form):
    firstname = TextField(validators=[
        Length(min=2, max=16, 
            message="First name must be between 2 and 16 characters"),
        Required(message='First name is required')])
    
    lastname = TextField(validators=[
        Length(min=2, max=16, 
            message="Last name must be between 2 and 16 characters"),
        Required(message='Last name is required')])
    
    email = TextField("Email Address", validators=[
        Required(message='Email is required'),
        Email(message="Invalid email address")])
    
    feedback = SelectField(validators=[
            Required("A feedback type is required"),
            AnyOf(["question", "comment", "bug"]), Required()],
        choices=[("question",'Question'),("comment",'Comment'),("bug",'Bug')])
    
    comment = TextAreaField(validators=[
            Length(min=1, max=300, 
                message="Please provide some feedback"), 
            Required("A comment is required")])
    
    def __init__(self, *args, **kwargs):
        super(ContactForm, self).__init__(*args, **kwargs)
        if self.firstname.data and \
           'first' == self.firstname.data.lower():
            self.firstname.data = ''
            
        if self.lastname.data and \
           'last' == self.lastname.data.lower():
            self.lastname.data = ''
            
        if self.email.data and \
           'i.e. ' in self.email.data:
            self.email.data = ''
    
    def to_dict(self):
        return dict(firstname=self.firstname.data,
                    lastname=self.firstname.data,
                    email=self.email.data,
                    feedback=self.feedback.data,
                    comment=self.comment.data)
Exemplo n.º 19
0
class InputFormSession(InputForm):
    """ Form used to specify the arguments needed when extracting the
    QTLs information from the input.
    """
    session = SelectField("MapQTL session",
                          validators=[Required()],
                          choices=[])

    def __init__(self, *args, **kwargs):
        """ Calls the default constructor with the normal arguments.
        If sessions are provided as kwargs, use it to fill in the
        choices of the select field.
        """
        super(InputFormSession, self).__init__(*args, **kwargs)
        if 'sessions' in kwargs and kwargs['sessions']:
            tmp = []
            for session in kwargs['sessions']:
                tmp.append((session, session))

            self.session.choices = tmp

        if 'sessions_label' in kwargs:
            if kwargs['sessions_label']:
                self.session.label = kwargs['sessions_label']
Exemplo n.º 20
0
class CompletedMatchForm(Form):
    team_id = SelectField(u'Team', coerce=int, validators=[Required()])
    match_id = HiddenIntegerField(u'Corresponding Match',
                                  validators=[NumberRange(min=1),
                                              Required()])
    opponent_id = SelectField(u'Opponent',
                              coerce=int,
                              choices=[],
                              validators=[Required()])
    competition_id = SelectField(u'Competition',
                                 coerce=int,
                                 validators=[Required()])
    server_id = SelectField(u'Server', coerce=int, validators=[Required()])
    date_played = MatchDateTimeField(u'Date', validators=[Required()])
    comments = TextAreaField(u'Comments', validators=[Optional()])

    final_result_method = SelectField(
        u'Final Result',
        coerce=int,
        validators=[Required()],
        choices=CompletedMatch.FinalResultChoices)

    rounds = FieldList(FormField(CompletedMatchRoundForm))
Exemplo n.º 21
0
class SshConfigForm(Form):

    next_page = HiddenField()
    id = IntegerField(widget=HiddenInput())

    name = TextField(u'Name', description=u'Ssh Config name. Unique',
                     validators=[Required(message=u'Name is required'),
                                 Regexp(u'^[a-zA-Z0-9\_\-\.\ ]{1,20}$', message=u'Incorrect name format'),
                                 Unique(SshConfig, SshConfig.name,
                                        message=u'The current name is already in use')])
    desc = TextField(u'Description', validators=[Required(message=u'Description is required')])
    port = IntegerField(u'Port', default=22,
                        validators=[Required(message=u'Port is required')])
    username = TextField(u'Username', default=u'root',
                         validators=[Required(message=u'Username is required')])
    password = TextField(u'Password',
                         validators=[Required(message=u'Password is required')])
    private_key = TextField(u'Private Key:',
                            description=u'Private filename in <code>PRIVATE_KEY_PATH</code>')
    groups = QuerySelectMultipleField(u'Group', description=u'Multiple Choice',
                                      query_factory=Group.query.all, get_label='desc',
                                      validators=[Required(message=u'Group is required')])
    submit = SubmitField(u'Submit', id='submit')
Exemplo n.º 22
0
class LoginForm(Form):
    email = TextField('Email address', [Required(), Email()])
    password = PasswordField('Password', [Required()])
Exemplo n.º 23
0
class LoginForm(Form):
    openid = TextField('openid', validators=[Required()])
    remember_me = BooleanField('remember_me', default=False)
Exemplo n.º 24
0
class PostForm(Form):
    post = TextField('post', validators=[Required()])
Exemplo n.º 25
0
class LoginForm(Form):
    name = fields.TextField(validators=[Required()])
    password = fields.PasswordField(validators=[Required(), validate_login])

    def get_user(self):
        return db.session.query(User).filter_by(name=self.name.data).first()
Exemplo n.º 26
0
class LoginForm(Form):
    username = TextField('Username', validators=[Required(), Length(max=32)])
Exemplo n.º 27
0
class SentenceInputForm(Form):
    sentence = TextAreaField("sentence", validators=[Required()])
Exemplo n.º 28
0
class TechnicianForm(Form):
    name = TextField("Name", validators=[Required(), Length(max=40)])
    login = TextField("Login", validators=[Required(), Length(max=10)])
    active = BooleanField('Active', default=True)
Exemplo n.º 29
0
class TechnicianAddForm(TechnicianForm):
    password = PasswordField("Password", validators=[Required()])
Exemplo n.º 30
0
class LoginForm(Form):
    email = TextField('email', validators=[Required()])
    password = PasswordField('password', validators=[Required()])