class Signup(Form): email = TextField('Email address', [ validators.Required( 'It’s okay, we won’t email you unless you want us to.' ), validators.Email('Um, that doesn’t look like an email address.'), ]) password = PasswordField('Password', [ validators.Required('How else will we know it’s really you?'), validators.EqualTo( 'retype', message= 'If you can’t type it twice now, you’ll never be able to log in with it.' ) ]) retype = PasswordField('Password (again)') consent = BooleanField('Accept the Terms', [ validators.Required('Is there something you don’t agree with?') ]) def validate_email(form, field): if models.User.query.filter_by(email=field.data).count(): raise validators.ValidationError( 'Looks like you’ve already registered. Try logging in instead.' )
class UserForm(Form): user = TextField('UserID', [validators.Required()]) group = PasswordField('GroupID', [validators.Required()]) def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) def validate(self): rv = Form.validate(self) if not rv: return False user = self.user.data group = self.group.data conn = MySQLdb.connect(host="localhost", user="******", db="pittbridge") cursor = conn.cursor() cursor.execute("SELECT * FROM groupids WHERE groupid = %s", group) res = cursor.fetchall() if not res: self.group.errors.append('Invalid group id') return False #keep track of users cursor.execute("REPLACE INTO users (userid, groupid) VALUES(%s,%s)", (user, group)) conn.commit() print user, group return True
class SignupForm(Form): firstname = TextField( "First name", [validators.Required("Please enter your first name.")]) lastname = TextField("Last name", [validators.Required("Please enter your last name.")]) email = TextField("Email", [ validators.Required("Please enter your email address."), validators.Email("Please enter your email address.") ]) password = PasswordField('Password', [validators.Required("Please enter a password.")]) submit = SubmitField("Create account") def __init__(self, *args, **kwargs): Form.__init__(self, *args, **kwargs) def validate(self): if not Form.validate(self): return False user = User.query.filter_by(email=self.email.data.lower()).first() if user: self.email.errors.append("That email is already taken") return False else: return True
class RegistrationForm(Form): full_name = TextField(lazy_gettext('School name'), [validators.Required(), validators.Length(min=4)] + forms.SCHOOL_FULL_NAME_VALIDATORS, description = lazy_gettext('School name.')) short_name = TextField(lazy_gettext('Short name'), [validators.Required()] + forms.SCHOOL_SHORT_NAME_VALIDATORS, description = lazy_gettext('Short name (lower case, all letters, dots and numbers).')) url = TextField(lazy_gettext('School URL'), [validators.Length(min=6, max=200), validators.URL(), validators.Required()], description = lazy_gettext('Address of your school.')) user_full_name = TextField(lazy_gettext('User name'), [validators.Required(), validators.Length(min=4)] + forms.USER_FULL_NAME_VALIDATORS, description = lazy_gettext('Your name and last name.')) user_login = TextField(lazy_gettext('Login'), [validators.Required()] + forms.USER_LOGIN_DEFAULT_VALIDATORS, description = lazy_gettext('Your new login (you can create more later).')) user_password = PasswordField(lazy_gettext('Password'), [validators.Required()] + forms.USER_PASSWORD_DEFAULT_VALIDATORS, description = lazy_gettext('Your access password.'))
class SpeakerForm(Form): name = fields.TextField(u'Name', [validators.Required()], description=u"Speaker's name") speech = fields.TextField(u'Speech title', [validators.Required()], description=u"Title for the speech") intro = fields.TextAreaField( u'Speech intro', [validators.Required()], description=u"A few words to introduce speech")
class LoginForm(Form): email = TextField( 'Email', validators=[validators.Required(), validators.Length(min=1)]) password = PasswordField( 'Password', validators=[validators.Required(), validators.Length(max=50)])
class ChangePassForm(Form): old_password = PasswordField('Password', [validators.Required()]) password = PasswordField('Password', [ validators.Length(min=6, max=35), validators.Required(), validators.EqualTo('confirm', message='Passwords must match') ]) confirm = PasswordField('Repeat Password')
class PageForm(Form): title = fields.TextField(u'Title', [validators.Required()], description=u'Page Title') slug = fields.TextField(u'Slug', [validators.Required()], description=u'Page Slug') content = fields.TextAreaField(u'Content', [validators.Required()], description='Content text') login_required = fields.BooleanField(u'Requires login')
class UpgradeForm(Form): sponsor = SelectField('Sponsor', choices=[(s.username, ''.join( (s.last_name, ', ', s.first_name))) for s in database.get_sponsors()], validators=[validators.Required()]) reason = TextAreaField('Reason for Upgrade', validators=[validators.Required()])
class LoginForm(Form): username = TextField( 'Username', validators=[validators.Required(), validators.Length(min=3, max=8)]) password = PasswordField( 'Password', validators=[validators.Required(), validators.Length(max=50)])
class RegistrationForm(Form): username = TextField('Username', [validators.Length(min=4, max=25)]) email = TextField('Email Address', [validators.Length(min=6, max=35)]) zipcode = TextField('Zipcode', [validators.Length(min=5, max=35)]) password = PasswordField('New Password', [ validators.Required(), validators.EqualTo('confirm', message='Passwords must match') ]) confirm = PasswordField('Repeat Password') accept_tos = BooleanField('I accept the TOS', [validators.Required()])
class ContactForm(Form): name = TextField("Name", [validators.Required("Name required")]) email = TextField("Email", [ validators.Required("Email required"), validators.Email("Email must be valid") ]) subject = TextField("Subject", [validators.Required("Subject required")]) message = TextAreaField("Message", [validators.Required("Message required")]) submit = SubmitField("Send")
class SetUser(wtforms.form.Form): email = TextField('Email address', [ validators.Required("It's okay, we won't email you unless you want us to."), validators.Email("Um, that doesn't look like an email address."), ]) password = PasswordField('Password', [ validators.Required("How else will we know it's really you?"), ]) retype = PasswordField('Password (again)', [ validators.EqualTo('password', message="If you can't type it twice now, you'll never be able to log in with it."), ])
class PostForm(Form): title = TextField("Title", [validators.Required("Please enter the title")]) text = TextAreaField( "Text", [validators.Required("Please provide the content for the title")]) tag = SelectMultipleField("Tag") submit = SubmitField("Create Post") def __init__(self, *args, **kwargs): kwargs['csrf_enabled'] = False Form.__init__(self, *args, **kwargs)
class ContactForm(Form): name = TextField("Name", [validators.Required("Plase enter your name.")]) email = TextField("Email", [ validators.Required("Please enter your email address."), validators.Email("Please enter your email address.") ]) subject = TextField("Subject", [validators.Required("Please enter a subject.")]) message = TextAreaField("Message", [validators.Required("Please enter a message.")]) submit = SubmitField("Send")
class RegisterForm(Form): email = TextField( 'Email', validators=[validators.Required(), validators.Length(min=1)]) password = PasswordField( 'Password', validators=[validators.Required(), validators.Length(max=50)]) name = TextField( 'Name', validators=[validators.Required(), validators.Length(min=3)])
class EditUserForm(Form): id = HiddenInteger('id') user = TextField( 'user', validators=[validators.Required(), validators.Length(min=3, max=64)]) email = TextField('email', validators=[validators.Required(), validators.Email()]) roles = MultiCheckboxField('roles', validators=[validators.Required()], coerce=int)
class GameForm(Form): all_teams = model.current_teams() game_date = DateField('Game Date', [validators.Required(message= (u'Game Date: mm/dd/yyyy'))], format= '%m/%d/%Y', description=u'Game Date(mm/dd/yyyy)') home_team = SelectField('Home', [validators.Required(message=(u'Select Team'))], choices=[(str(i.id),i.teamname) for i in all_teams], description=u'Home Team') away_team = SelectField('Away', [validators.Required(message=(u'Select Team'))], choices=[(str(i.id),i.teamname) for i in all_teams], description=u'Opponent') home_score = IntegerField('Home Score', [validators.Optional()], description=u'Home Score') away_score = IntegerField('Away Score', [validators.Optional()], description=u'Opponent Score')
class ResetForm(Form): password = PasswordField('Password', validators=[ validators.Required(), validators.Length(min=8, max=50), validators.CrackLib() ]) pw_confirm = PasswordField('Confirm Password', validators=[ validators.Required(), validators.Length(min=8, max=50), validators.EqualTo( 'password', message='Passwords do not match.') ])
class ProductForm(Form): name = TextField( 'name', validators=[validators.Required(), validators.Length(min=3, max=64)]) price = DecimalField( 'price', validators=[validators.NumberRange(min=0.1, max=100.0)]) slot = IntegerField('slot', validators=[ validators.Required(), validators.NumberRange(min=1, max=5) ]) stock = IntegerField('stock', validators=[validators.Required()]) alert_level = IntegerField('alert_level', validators=[validators.Required()])
class RequestResetForm(Form): username = TextField('Username', validators=[ validators.Required(), validators.Length(min=3, max=8), validators.EntryExists(User, User.username) ]) dob = TextField('Date of Birth (DD/MM/YYYY)', validators=[ validators.Required(), validators.Date( format='%m/%d/%Y', message='Invalid format. Please use mm/dd/yy.') ]) birth_city = TextField('Birth City', validators=[validators.Required()])
class TagForm(Form): tag = TextField('Tag Name', [validators.Required('Enter tag name')]) submit = SubmitField("Create Tag") def __init__(self, *args, **kwargs): kwargs['csrf_enabled'] = False Form.__init__(self, *args, **kwargs)
class QuestionForm(Form): """Form that receives questions from users to the "Answer" tool""" theme = SelectField( _('Theme'), [ validators.Required( message=_(u'You need to choose one of the options above')) ], ) title = TextField( _('Contribution title'), [ validators.Length(min=5, message=_( u'Your title is too short! It needs to have ' u'at least 5 chars')), validators.Length(max=256, message=_( u'Your title is too long! It needs to have ' u'at most 256 chars')) ], ) question = TextField( _('Content'), [ validators.Length( min=5, message=_(u'Your contribution is too short! It needs to have ' u'at least 50 chars')), ], )
def request_reset(): form = TextField('Email', validators=[validators.Required()]) if form.is_submitted(): if form.validate_on_submit(): if User.query.filter(User.name == form.name.data).count() > 0: flash( "That name is already in use, please choose a different name." ) render_template("register.html", form=form) if User.query.filter(User.email == form.email.data).count() > 0: flash( "That email is already in use. Are you already registered?" ) render_template("register.html", form=form) u = User(email=form.email.data, password=form.password.data, name=form.name.data, user_type=User.TEACHER) db.session.add(u) db.session.commit() flash('Registration successful!') return redirect(url_for("index")) else: flash("There was an error with your submission") return render_template("register.html", form=form) return render_template("register.html", form=form)
def labstaff_add_user(): # Labstaff have the ability to choose 'staff' as a sponsor RegisterForm.sponsor = SelectField('Sponsor', choices=[ (s.username, ''.join( (s.last_name, ', ', s.first_name))) for s in database.get_sponsors(True) ], validators=[validators.Required()]) form = RegisterForm() if form.is_submitted(): if form.validate_on_submit(): user = database.User(form.username.data, form.password.data) user.first_name = form.first_name.data user.last_name = form.last_name.data user.dob = form.dob.data user.email = form.email.data user.sponsor = form.sponsor.data user.grad_date = form.grad_date.data user.status = 'pending_create' if form.acct_type.data == 'acad': user.add_domain('acad') else: user.add_domains('acad', 'research') db.session.add(user) db.session.commit() flash('User account created.') return redirect(url_for("index")) else: return render_template( "labstaff_add_user.html", form=form, error="There was an error with your submission") return render_template("labstaff_add_user.html", form=form)
class ResetPasswordForm(Form): password = f.PasswordField('New password', [ v.Required(), v.Length(min=8, message="It's probably best if your password is longer than 8 characters."), v.EqualTo('confirm', message="Passwords must match.") ]) confirm = f.PasswordField('Confirm password')
class ParametersForm(Form): oxigen_min = DecimalField(u'Oxígeno Mínimo', [ validators.Required("Campo obligatorio"), validators.NumberRange(0.01, 99.99, "El valor debe estar entre %(min)s y %(max)s"), ]) oxigen_max = DecimalField(u'Oxígeno Máximo', [ validators.Required("Campo obligatorio"), validators.NumberRange(0.01, 99.99, "El valor debe estar entre %(min)s y %(max)s"), ]) cloudiness_max = IntegerField(u'Turbiedad Máxima', [ validators.Required("Campo obligatorio"), validators.NumberRange(1, 9999, "El valor debe estar entre %(min)s y %(max)s"), ])
class SignupForm(BaseDataForm, BasePasswordForm): """Wtform that builds the signup form""" # email_confirmation = TextField( # _('Email confirmation'), # [validators.Email(message=_(u'That\'s not a valid email address.')), # ] # ) accept_tos = BooleanField( _('Have you read and accepted our ' '<a href="javascript:auth.toggleSignupTab(\'tos\')">' 'Terms of use</a>?'), [validators.Required(),], default=True, ) receive_email = BooleanField( _('I want to receive updates by email.'), default=True, ) receive_sms = BooleanField( _('I want to receive updates by sms.'), default=False, )
class Login(Form): email = TextField( 'Email address', validators=[validators.Email('Please supply an email address.')]) password = PasswordField( 'Password', validators=[validators.Required('Please supply a password.')])
class LoginForm(Form): username = TextField('username', [validators.Required()]) password = PasswordField('password', [validators.Required()]) def validate(self): if not super(LoginForm, self).validate(): return False user = User.authenticate(username=self.username.data, password=self.password.data) if not user: self.username.errors.append('Invalid details.') return False self.user = user return True