class RoomForm(IndicoForm): name = StringField(_(u'Name')) site = StringField(_(u'Site')) building = StringField(_(u'Building'), [DataRequired()]) floor = StringField(_(u'Floor'), [DataRequired()]) number = StringField(_(u'Number'), [DataRequired()]) longitude = FloatField(_(u'Longitude'), [Optional()]) latitude = FloatField(_(u'Latitude'), [Optional()]) is_active = BooleanField(_(u'Active'), default=True) is_reservable = BooleanField(_(u'Public'), default=True) reservations_need_confirmation = BooleanField(_(u'Confirmations')) notification_for_assistance = BooleanField(_(u'Assistance')) notification_before_days = IntegerField(_(u'Send booking reminders X days before (single/daily)'), [Optional(), NumberRange(min=1, max=30)]) notification_before_days_weekly = IntegerField(_(u'Send booking reminders X days before (weekly)'), [Optional(), NumberRange(min=1, max=30)]) notification_before_days_monthly = IntegerField(_(u'Send booking reminders X days before (monthly)'), [Optional(), NumberRange(min=1, max=30)]) notifications_enabled = BooleanField(_(u'Reminders enabled'), default=True) booking_limit_days = IntegerField(_(u'Maximum length of booking (days)'), [Optional(), NumberRange(min=1)]) owner = PrincipalField(_(u'Owner'), [DataRequired()], allow_external=True) key_location = StringField(_(u'Where is key?')) telephone = StringField(_(u'Telephone')) capacity = IntegerField(_(u'Capacity'), [Optional(), NumberRange(min=1)], default=20) division = StringField(_(u'Department')) surface_area = IntegerField(_(u'Surface area'), [Optional(), NumberRange(min=0)]) max_advance_days = IntegerField(_(u'Maximum advance time for bookings'), [Optional(), NumberRange(min=1)]) comments = TextAreaField(_(u'Comments')) delete_photos = BooleanField(_(u'Delete photos')) large_photo = FileField(_(u'Large photo')) available_equipment = IndicoQuerySelectMultipleCheckboxField(_(u'Equipment'), get_label=_get_equipment_label, modify_object_list=_group_equipment) # attribute_* - set at runtime bookable_hours = FieldList(FormField(_TimePair), min_entries=1) nonbookable_periods = FieldList(FormField(_DateTimePair), min_entries=1)
class RoomForm(IndicoForm): name = StringField(_(u'Name')) site = StringField(_(u'Site')) building = StringField(_(u'Building'), [DataRequired()]) floor = StringField(_(u'Floor'), [DataRequired()]) number = StringField(_(u'Number'), [DataRequired()]) longitude = FloatField(_(u'Longitude'), [Optional()]) latitude = FloatField(_(u'Latitude'), [Optional()]) is_active = BooleanField(_(u'Active'), default=True) is_reservable = BooleanField(_(u'Public'), default=True) reservations_need_confirmation = BooleanField(_(u'Confirmations')) notification_for_assistance = BooleanField(_(u'Assistance')) notification_before_days = IntegerField( _(u'Notification on booking start - X days before'), [Optional(), NumberRange(min=0, max=9)], default=0) notification_for_responsible = BooleanField( _(u'Notification to responsible, too')) owner_id = HiddenField(_(u'Responsible user'), [DataRequired()]) key_location = StringField(_(u'Where is key?')) telephone = StringField(_(u'Telephone')) capacity = IntegerField( _(u'Capacity'), [DataRequired(), NumberRange(min=1)], default=20) division = StringField(_(u'Department')) surface_area = IntegerField(_(u'Surface area'), [Optional(), NumberRange(min=0)]) max_advance_days = IntegerField( _(u'Maximum advance time for bookings'), [Optional(), NumberRange(min=1)]) comments = TextAreaField(_(u'Comments')) delete_photos = BooleanField(_(u'Delete photos')) large_photo = FileField(_(u'Large photo')) small_photo = FileField(_(u'Small photo')) available_equipment = IndicoQuerySelectMultipleCheckboxField( _(u'Equipment'), get_label=_get_equipment_label, modify_object_list=_group_equipment) # attribute_* - set at runtime bookable_hours = FieldList(FormField(_TimePair), min_entries=1) nonbookable_periods = FieldList(FormField(_DateTimePair), min_entries=1) def validate_large_photo(self, field): if not field.data and self.small_photo.data: raise ValidationError( _(u'When uploading a small photo you need to upload a large photo, too.' )) def validate_small_photo(self, field): if not field.data and self.large_photo.data: raise ValidationError( _(u'When uploading a large photo you need to upload a small photo, too.' ))
class ArticleForm(FlaskForm): """Form to create the article in the database """ title = StringField('Article Title', render_kw={'placeholder': "Enter the article title"}, validators=[DataRequired()]) link = StringField( 'Article link', render_kw={'placeholder': "Enter the article link"}, validators=[DataRequired(), URL(message='Must be a valid URL')]) year = IntegerField( 'Publication Year', render_kw={'placeholder': "Enter the publication year of the article"}, validators=[DataRequired()]) journal = StringField('Journal', render_kw={ 'placeholder': "Journal in which the article was published" }, validators=[DataRequired()]) authors = FieldList(FormField(AuthorForm), min_entries=1, max_entries=20) submit = SubmitField('Save General Informations')
class OrderForm(FlaskForm): customer_name = StringField('Name', validators=[DataRequired()]) latitude = FloatField("Latitude", validators=[DataRequired()]) longitude = FloatField("Longitude", validators=[DataRequired()]) preferred_max_distance = IntegerField( "Preferred maximum distance (in kilometers)", validators=[DataRequired()]) menu = FieldList(FormField(FoodQuantityForm), min_entries=1) submit = SubmitField('Submit')
class ElectionForm(FlaskForm): name = StringField( 'Election Name', validators=[DataRequired()]) description = TextAreaField('Election Description') date_of_election = DateField('Date of Election', format='%Y-%m-%d') time_of_election = DateTimeField('Time of Election', format='%H:%M') candidates = FieldList(FormField(CandidateForm), min_entries=2, max_entries=10) number_of_voters = IntegerField( 'Number of Voters', validators=[DataRequired()]) password = PasswordField('Password') submit = SubmitField('Generate Link')
class ProctorSessionForm(FlaskForm): session_name = StringField("Session Name", validators=[InputRequired()]) start_time = DateTimeLocalField("Start Time", format='%Y-%m-%dT%H:%M', validators=[InputRequired()]) end_time = DateTimeLocalField("End Time", format='%Y-%m-%dT%H:%M', validators=[InputRequired()]) session_users = FieldList(FormField(SessionUserForm), min_entries=2) submit = SubmitField("Create!") def validate_session_name(form, field): session_name = field.data if ProctorSession.query.filter_by(name=session_name).first(): raise ValidationError("Name Taken, choose another")
class PasteForm(FlaskForm): id = IntegerField('id') name = StringField('name', [validators.Length(min=1, max=20)]) content = TextAreaField('content', [validators.Length(min=1, max=5000)]) author = StringField('author', [validators.Length(min=1, max=20)]) modules = FieldList(FormField(ModuleForm)) def populate(self, paste): self.id.data = paste.id self.name.data = paste.name self.content.data = paste.content self.author.data = paste.author self.populateModules(paste.modules) def populateModules(self, modules): for module in modules: module_form = ModuleForm() module_form.populate(module) self.modules.append_entry(module_form)
class BillForm(FlaskForm): date = DateField(_("Date"), validators=[DataRequired()], default=datetime.now) what = StringField(_("What?"), validators=[DataRequired()]) payer = SelectField(_("Payer"), validators=[DataRequired()], coerce=int) amount = CalculatorStringField(_("Amount paid"), validators=[DataRequired()]) external_link = URLField( _("External link"), validators=[Optional()], description=_("A link to an external document, related to this bill"), ) billowers = FieldList(FormField(BillOwersForm), min_entries=1) submit = SubmitField(_("Submit")) submit2 = SubmitField(_("Submit and add a new one")) advanced = False def validate_billowers(form, billowers): participants = 0 # must have at least one billower for form_billower in billowers: if form_billower.included.data is True: participants += 1 if participants >= 1: pass else: raise ValidationError( _("At least one participant should be included in the bill")) def save(self, bill): bill.payer_id = self.payer.data bill.amount = self.amount.data bill.what = self.what.data bill.external_link = self.external_link.data bill.date = self.date.data new_billowers = [] for form_billower in self.billowers: billower_already_exists = False if bill.owers != []: for old_billower in bill.billowers: if old_billower.person_id == int( form_billower.person_id.data): billower_already_exists = True if form_billower.included.data is True: # rather than checking if the value is update, we're just assigning it old_billower.person_id = form_billower.person_id.data old_billower.bill_id = bill.id old_billower.weight = form_billower.weight.data.__int__( ) new_billowers.append(old_billower) if billower_already_exists is False: if form_billower.included.data is True: new_billower = BillOwers() new_billower.person_id = form_billower.person_id.data new_billower.bill_id = bill.id new_billower.weight = form_billower.weight.data.__int__() new_billowers.append(new_billower) bill.billowers = new_billowers return bill def fake_form(self, bill, project): bill.payer_id = self.payer bill.amount = self.amount bill.what = self.what bill.external_link = "" bill.date = self.date bill.billowers = [ Person.query.get(ower, project) for ower in self.payed_for ] return bill def validate_amount(self, field): if field.data == 0: raise ValidationError(_("Bills can't be null"))
class QuizForm(FlaskForm): """Quiz form - simply 10 Questions.""" questions = FieldList(FormField(QuestionForm), min_entries=10)
class ExamFormForm(FlaskForm): proctor_id = SelectField("Proctor Session", coerce=int, validators=[InputRequired()]) exam_questions = FieldList(FormField(ExamQuestionForm), min_entries=1) submit = SubmitField("Create Exam Form")
class Rcads_form(Form): age = IntegerField(default=99) qs = FieldList(FormField(Rcads_q))
class ListResultForm(FlaskForm): """Form to submit list of policy-targets to database """ list = FieldList(FormField(ResultForm), min_entries=1, max_entries=20) submit = SubmitField('Save Results')