class TalkForm(Form): title = TextField(u'Název', validators=[Required()]) description = TextField(u'Popisek', validators=[Required()], widget=TextArea()) purpose = TextField(u'Pro koho je určena', validators=[Required()], widget=TextArea())
class NoteForm(Form): name = TextField('Name', validators=[Required()]) text = TextAreaField('Note', validators=[Required()]) pad = SelectField('Pad', choices=[], coerce=int) # @TODO use wtforms.ext.sqlalchemy.fields.QuerySelectField? def __init__(self, user=None, **kwargs): super(NoteForm, self).__init__(**kwargs) self.pad.choices = [(0, '---------')] + [ (p.id, p.name) for p in Pad.query.filter_by(user=user) ]
class SignupForm(Form): email = TextField('Email', validators=[Required(), Email()]) password = PasswordField('Password', validators=[Required()]) repeat_password = PasswordField( 'Repeat Password', validators=[ Required(), EqualTo('password', message="Your passwords do not match") ]) def validate_email(self, field): if User.query.filter_by(email=field.data).count(): raise ValidationError('User with this email is already signed up')
class ProjectForm(EditProjectForm): id = TextField(_("Project identifier"), validators=[Required()]) password = PasswordField(_("Private code"), validators=[Required()]) submit = SubmitField(_("Create the project")) def validate_id(form, field): form.id.data = slugify(field.data) if (form.id.data == "dashboard") or Project.query.get(form.id.data): raise ValidationError( Markup( _("The project identifier is used " "to log in and for the URL of the project. " "We tried to generate an identifier for you but a project " "with this identifier already exists. " "Please create a new identifier " "that you will be able to remember.")))
class PasswordReminder(Form): id = TextField(_("Project identifier"), validators=[Required()]) submit = SubmitField(_("Send me the code by email")) def validate_id(form, field): if not Project.query.get(field.data): raise ValidationError(_("This project does not exists"))
class MemberForm(Form): name = TextField(_("Name"), validators=[Required()]) weight = CommaDecimalField(_("Weight"), default=1) submit = SubmitField(_("Add")) def __init__(self, project, edit=False, *args, **kwargs): super(MemberForm, self).__init__(*args, **kwargs) self.project = project self.edit = edit def validate_name(form, field): if field.data == form.name.default: raise ValidationError(_("User name incorrect")) if (not form.edit and Person.query.filter( Person.name == field.data, Person.project == form.project, Person.activated == True).all()): raise ValidationError(_("This project already have this member")) def save(self, project, person): # if the user is already bound to the project, just reactivate him person.name = self.name.data person.project = project person.weight = self.weight.data return person def fill(self, member): self.name.data = member.name self.weight.data = member.weight
class ChangePasswordForm(Form): old_password = PasswordField('Old Password', validators=[Required()]) new_password = PasswordField('New Password', validators=[Required()]) repeat_new_password = PasswordField( 'Repeat New Password', validators=[ Required(), EqualTo('new_password', message="Your passwords don't match") ]) def __init__(self, **kwargs): super(ChangePasswordForm, self).__init__(**kwargs) self.user = kwargs['user'] def validate_old_password(self, field): if not self.user.check_password(field.data): raise ValidationError('Incorrect old password')
class RegisterForm(Form, EmailFormMixin, PasswordFormMixin, PasswordConfirmFormMixin): " The default register form. " username = TextField(_('UserName'), [Required(message=_('Required'))]) # submit = SubmitField(_("Register")) def to_dict(self): return dict(email=self.email.data, password=self.password.data)
class EditProjectForm(Form): name = TextField(_("Project name"), validators=[Required()]) password = TextField(_("Private code"), validators=[Required()]) contact_email = TextField(_("Email"), validators=[Required(), Email()]) def save(self): """Create a new project with the information given by this form. Returns the created instance """ project = Project(name=self.name.data, id=self.id.data, password=self.password.data, contact_email=self.contact_email.data) return project def update(self, project): """Update the project with the information from the form""" project.name = self.name.data project.password = self.password.data project.contact_email = self.contact_email.data return project
class BillForm(Form): date = DateField(_("Date"), validators=[Required()], default=datetime.now) what = TextField(_("What?"), validators=[Required()]) payer = SelectField(_("Payer"), validators=[Required()], coerce=int) amount = CommaDecimalField(_("Amount paid"), validators=[Required()]) payed_for = SelectMultipleField(_("For whom?"), validators=[Required()], widget=select_multi_checkbox, coerce=int) submit = SubmitField(_("Submit")) submit2 = SubmitField(_("Submit and add a new one")) def save(self, bill, project): bill.payer_id = self.payer.data bill.amount = self.amount.data bill.what = self.what.data bill.date = self.date.data bill.owers = [ Person.query.get(ower, project) for ower in self.payed_for.data ] return bill def fill(self, bill): self.payer.data = bill.payer_id self.amount.data = bill.amount self.what.data = bill.what self.date.data = bill.date self.payed_for.data = [int(ower.id) for ower in bill.owers] def set_default(self): self.payed_for.data = self.payed_for.default def validate_amount(self, field): if field.data == 0: raise ValidationError(_("Bills can't be null"))
class ResetPasswordForm(Form, EmailFormMixin, PasswordFormMixin, PasswordConfirmFormMixin): " The default reset password form. " token = HiddenField(validators=[Required()]) submit = SubmitField(_("Reset Password")) def __init__(self, *args, **kwargs): super(ResetPasswordForm, self).__init__(*args, **kwargs) if request.method == 'GET': self.token.data = request.args.get('token', None) self.email.data = request.args.get('email', None) def to_dict(self): return dict(token=self.token.data, email=self.email.data, password=self.password.data)
class StatForm(Form): stat = HiddenField('stat_select', id='stat_select', validators=[Required()]) benchmarks = SelectMultipleField('benchmark_select', id='benchmark_select', validators=[Required()]) runs = SelectMultipleField('run_select', id='run_select', validators=[Required()], coerce=str) normalize = BooleanField('normalize', id='normalize', validators=[Required()]) average = BooleanField('average', id='average', validators=[Required()]) hmean = BooleanField('hmean', id='hmean', validators=[Required()]) submit = SubmitField('Update', id='Update')
class SigninForm(Form): email = TextField('Email', validators=[Required(), Email()]) password = PasswordField('Password', validators=[Required()])
class ForgotPasswordForm(Form): email = TextField('Email', validators=[Required(), Email()]) def validate_email(self, field): if not User.query.filter_by(email=field.data).count(): raise ValidationError('No user with given email found')
class EmailForm(Form): email = TextField('E-mail', validators=[Required(), Email()])
class PadForm(Form): name = TextField('Name', validators=[Required()])
class BasicForm(Form): fullname = TextField(u'Jméno', validators=[Required()]) password = TextField('Heslo', validators=[Required()])
class PasswordFormMixin(): password = PasswordField( _("Password"), validators=[Required(message=_("Password not provided"))])
class NewStoreForm(Form): name = TextField('Name', validators=[Required()]) address = TextField('Address', validators=[Required()]) city = TextField('City', validators=[Required()]) state = TextField('State', validators=[Required()]) zip_code = TextField('Zip Code', validators=[Required()])
class EmailFormMixin(): email = TextField(_('Email address'), validators=[ Required(message=_("Email not provided")), Email(message=_("Invalid email address")) ])
class PasswordForm(Form): password = TextField('Heslo', validators=[Required(), EqualTo( 'confirm', message=u'Hesla se musí shodovat')]) confirm = TextField(u'Potvrzení', validators=[])
class LoginForm(Form): email = TextField('Email', [validators.Length(min=6, max=35), validators.Email()]) password = PasswordField('Password', [Required()])
class AuthenticationForm(Form): id = TextField(_("Project identifier"), validators=[Required()]) password = PasswordField(_("Private code"), validators=[Required()]) submit = SubmitField(_("Get in"))
class RegistrationForm(Form): name = TextField('Name', [validators.Length(min=1, max=25)]) email = TextField('Email', [validators.Length(min=6, max=35), validators.Email()]) password = PasswordField('Password', [Required()])
class CreateArchiveForm(Form): name = TextField(_("Name for this archive (optional)"), validators=[]) start_date = DateField(_("Start date"), validators=[Required()]) end_date = DateField(_("End date"), validators=[Required()], default=datetime.now)
class NewProductForm(ProductFormMixin, Form): name = TextField('Name', validators=[Required()]) categories = SelectMultipleField('Categories', coerce=int, validators=[Required()])
class LoginForm(Form): email = TextField('E-mail', validators=[Required(), Email()]) password = TextField('Heslo', validators=[Required()])