class CustomerForm(ModelForm): volunteer_date = DateTimeField(format='%m/%d/%Y %H:%M', validators=(validators.Optional(), )) class Meta: datetime_format = '%m/%d/%Y' model = CustomerFamily field_args = { 'id': { 'validators': [validators.Optional()] }, 'city': { 'validators': [validators.InputRequired()] }, 'state': { 'validators': [validators.InputRequired()] }, 'zip': { 'validators': [validators.InputRequired()] }, 'datecreated': { 'validators': [validators.Optional()] } } dependents = ModelFieldList(FormField(DependentForm), min_entries=2)
class TriggerForm(ModelForm): class Meta: model = Trigger """GUI: trigger build form used in views""" question_id = HiddenInteger("Question id") # conditions conditions = ModelFieldList(FormField(TriggerConditionForm)) # if true yes_type = SelectField("Type", choices=TRIGGER_KINDS) dest_yes = QuerySelectField( "Destination", get_pk=lambda a: a.id, get_label=lambda a: a.body, allow_blank=True, ) payload_yes = TextAreaField("Message") alert_yes = BooleanField("Alert") # if false no_type = SelectField("Type", choices=TRIGGER_KINDS) dest_no = QuerySelectField( "Destination", get_pk=lambda a: a.id, get_label=lambda a: a.body, allow_blank=True, ) payload_no = TextAreaField("Message") alert_no = BooleanField("Alert")
class ProjectAssignForm(FlaskForm): name = StringField('Name', validators=[DataRequired()]) description = TextAreaField('Description', validators=[DataRequired()]) project_type = SelectField('Project type', choices=[('Ad-hoc', 'Ad-hoc'), ('Recurrent', 'Recurrent')], default=None) project_phase = SelectField('Project phase', choices=[(i, i) for i in ('Conception', 'Planning', 'Development', 'Close')], default=None) department = QuerySelectField(query_factory=lambda: Department.query.all(), get_label='description', allow_blank=True) project_lead = QuerySelectField( query_factory=lambda: Employee.query.all(), get_label=lambda employee: '{}, {} ({})'.format( employee.last_name, employee.first_name, employee.role), allow_blank=True) members = ModelFieldList(FormField(EmployeeForm), min_entries=1, model=Employee) start_date = DateField('Project start date', format="%m/%d/%Y", validators=[DataRequired()]) tags = TagField('Tags', description='Separate multiple tags with commas.') progress_note = TextAreaField('Progress note')
class ServerForm(ModelForm): class Meta: model = Server variables = ModelFieldList(FormField(VariableForm, widget=TableWidget(with_table_tag=False)), min_entries=1) create_server = SubmitField('Create Server') add_variable = SubmitField('Add Variable') delete_variable = SubmitField('Remove Variable')
class EventForm(ModelForm): class Meta: model = self.Event locations = ModelFieldList( FormField(LocationForm), population_strategy='update' )
class HikeForm(_PrintableForm): class Meta(object): model = Hike only = [ 'method', 'date', ] destination_id = ModelFieldList(FormField(HikeDestinationForm))
class LERForm(FlaskForm): facilities = SelectMultipleField( "Select Facilities", coerce=int, validators=[DataRequired()], render_kw={'data-placeholder': "Select affected facilities..."}) title = StringField('Title', validators=[Length(0, 200), DataRequired()], render_kw={"placeholder": "Up to 200 characters"}) event_date = DateField('Event Date', validators=[DataRequired()], format="%m/%d/%Y", render_kw={"placeholder": "mm/dd/yyyy"}) operating_mode = SelectField('Operating Mode', validators=[DataRequired()]) power_level = IntegerField( 'Power Level', render_kw={"placeholder": "e.g., 100"}, validators=[InputRequired(), NumberRange( min=0, max=100, )]) cfrs = SelectMultipleField( "Report Submitted Pursuant to Requirements of 10 CFR: (Select all that apply)", coerce=int, validators=[DataRequired()], render_kw={'data-placeholder': "Select all that apply..."}) components = ModelFieldList(FormField(AddComponentForm), min_entries=1) supplement_expected = BooleanField("Supplemental Report Expected") supplement_date = DateField("Expected Supplement Submission Date", format="%m/%d/%Y", validators=[Optional()], render_kw={"placeholder": "mm/dd/yyyy"}) abstract = TextAreaField("Abstract", validators=[DataRequired()]) body = CKTextAreaField("LER Text", validators=[DataRequired()]) submit = SubmitField('Create LER') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.facilities.choices = [ (docket.id, '{} - {}'.format(docket.docket, docket.facility_name)) for docket in Facility.query.order_by( Facility.facility_name).all() if docket.docket.startswith('050') ] self.cfrs.choices = [(cfr.id, cfr.cfr) for cfr in CFR.query.order_by(CFR.cfr).all()] self.operating_mode.choices = [('N/A', 'N/A'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')] # # class TestForm(FlaskForm): # text = CKTextAreaField("Text")
def city(): city_form = forms_classes["CitiesForm"]() class_feature_form = forms_classes["Class_featureForm"] city_form.class_features = ModelFieldList( FormField(class_feature_form, min_entries=2)) city_form.class_features.append_entry() city_form.class_features.append_entry() print(city_form.class_features) """ if form.validate_on_submit(): return redirect(url_for('success')) """ return render_template('index.html', form=city_form)
class TeamForm(ModelForm, Form): class Meta: model = Team members = ModelFieldList(FormField(MemberForm), min_entries=1, max_entries=10) accept_terms = BooleanField('accept_terms', default=False, validators=[Required()]) submit = SubmitField('Skicka anmälan!') def validate_members(self, members): remaining_tickets_for_type = [ logic.get_number_of_tickets_for_this_type_left(ind) for ind, ticket in enumerate(app.config['FLUMRIDE']['ticket_types']) ] team_tickets = [x.data['ticket_type'] for x in members] remaining_tickets_after_transaction = [ left - team_tickets.count(index) for index, left in enumerate(remaining_tickets_for_type) ] error = False for member in members: if member.data['ticket_type'] == None: #Don't do an .append() here since we dont want the default [not a valid choice] error to appear member.ticket_type.errors = [ 'Du glömde ange biljettyp för denna medlemen' ] error = True continue if remaining_tickets_after_transaction[ member.data['ticket_type']] < 0: member.ticket_type.errors.append( 'Du har anget fler av denna biljettyp än vad som finns kvar' ) error = True #Verify all person_numbers are unique person_numbers = [x.data['person_number'] for x in members] duplicate_person_numbers = [ x for n, x in enumerate(person_numbers) if x in person_numbers[:n] ] if duplicate_person_numbers: for member in members: if member.data['person_number'] in duplicate_person_numbers: member.person_number.errors.append( 'Du har med samma personnummer flera gånger') error = True if error: raise ValidationError("error in input")
class EditProviderForm(ModelForm): class Meta: model = Provider provider_platforms = ModelFieldList(FormField(ProviderPlatformForm)) platform_to_add = QuerySelectField( "Platform", get_label=lambda p: p.name, validators=[validators.Optional()], render_kw={"class": "form-control select2"}, allow_blank=True, ) add_platform = SubmitField( "Add", render_kw={"class": "btn btn-success btn-sm btn-block"})
class LogForm(Form): class Meta(object): model = OSIRISLog all_fields_optional = True support_astronomer = QuerySelectField(query_factory=Person.query.all, get_label='name', allow_blank=True) observing_assistant = QuerySelectField(query_factory=Person.query.all, get_label='name', allow_blank=True) # observers = QuerySelectField(query_factory=Person.query.all, get_label='name', allow_blank=True) rows = ModelFieldList(FormField(LogRowDatasetForm, default=lambda: OSIRISLogDataset()), population_strategy='replace', min_entries=1)
class CheckoutForm(ModelForm): class Meta: datetime_format = '%m/%d/%Y %H:%M:%S' model = Visit include = ['id', 'family_id'] field_args = { 'id': { 'validators': [validators.Optional()] }, 'checkin': { 'validators': [validators.InputRequired()] }, 'checkout': { 'validators': [validators.Optional()] }, 'family_id': { 'validators': [validators.InputRequired()] } } items = ModelFieldList(FormField(ShoppingItemForm), min_entries=0)
class DocumentAnalysisForm(ModelForm): class Meta: model = Document only = ['flagged', 'notes'] sources = ModelFieldList(FormField(DocumentSourceForm)) def __init__(self, *args, **kwargs): # pass the document into the DocumentSourcesForm constructor self.sources.args[0].kwargs['form_kwargs'] = { 'document': kwargs.get('obj') } super(DocumentAnalysisForm, self).__init__(*args, **kwargs) @property def non_new_sources(self): return [s.form for s in self.sources if not s.form.is_new()] @property def new_sources(self): return [s.form for s in self.sources if s.form.is_new()]
class ArtifactForm(ModelForm): """Form for creating and editting artifacts""" class Meta: model = Artifact prerequisites = CommaSepListField( "Prerequisites", separator=",", to_lowercase=True ) concept = StringField('Main Concept', validators=[DataRequired()]) source = FormField(SourceForm) title = StringField('Title', validators=[DataRequired()]) description = TextAreaField('Description', validators=[DataRequired()]) mediatype = SelectField('Mediatype', choices=Artifact.mediatype_options(), validators=[DataRequired()], coerce=int) duration = SelectField('Duration', choices=Artifact.duration_options(), validators=[DataRequired()], coerce=int) vote_count = IntegerField() vote_sum = IntegerField() chunks = ModelFieldList(FormField(ChunkForm), min_entries=1) create = SubmitField('Create')
class HuntForm(ModelForm): class Meta: model = models.Hunt name = StringField('Name', [validators.Length(min=4)]) items = ModelFieldList(FormField(ItemForm), min_entries=1)
class EventForm(ModelForm): class Meta: model = self.Event locations = ModelFieldList(FormField(LocationForm))
class Laborator(ModelFormMeta): class Meta: model = LaboratorForm Students = ModelFieldList(FormField(StudentForm))
class EventForm(ModelForm): class Meta: model = Event locations = ModelFieldList(FormField(LocationForm, min_entries=2))
class ViewForm(ModelForm, TranslatedForm): class Meta: model = View columns = ModelFieldList(FormField(ViewColumnForm)) groupers = ModelFieldList(FormField(ViewGrouperForm)) sorters = ModelFieldList(FormField(ViewSorterForm)) columns_choices = None filters = ModelFormField(ViewFiltersForm) def set_columns(self, columns): for column in columns: self.columns.append_entry(column) self.columns[-1].column.choices = copy.copy(self.columns_choices) if ('', '') in self.columns[-1].column.choices: self.columns[-1].column.choices.remove(('', '')) def set_groupers(self, groupers): for grouper in groupers: self.groupers.append_entry(grouper) self.groupers[-1].column.choices = self.columns_choices def set_sorters(self, sorters): for sorter in sorters: self.sorters.append_entry(sorter) self.sorters[-1].column.choices = self.columns_choices def get_view(self): view = View() view.title = self.title.data view.link_name = self.link_name.data view.datasource = self.datasource.data view.buttontext = self.buttontext.data view.reload_intervall = self.reload_intervall.data view.layout_number_columns = self.layout_number_columns.data return view def set_columns_choices(self, choices, update=False): self.columns_choices = choices if update: for column_form in self.columns: column_form.column.choices = choices for sorter_form in self.sorters: sorter_form.column.choices = choices for grouper_form in self.groupers: grouper_form.column.choices = choices def get_columns(self, view_id): columns = [] for column_form in self.columns: column = ViewColumn() column.column = column_form.column.data column.parent_id = view_id columns.append(column) return columns def get_groupers(self, view_id): groupers = [] for grouper_form in self.groupers: grouper = ViewGrouper() grouper.column = grouper_form.column.data grouper.parent_id = view_id groupers.append(grouper) return groupers def get_sorters(self, view_id): sorters = [] for sorter_form in self.sorters: sorter = ViewSorter() sorter.column = sorter_form.column.data sorter.sorter_option = sorter_form.sorter_option.data sorter.parent_id = view_id sorters.append(sorter) return sorters def get_filters(self): return self.filters.get_filters()
class CurriculumUnitUnionForm(ModelForm): att_marks = ModelFieldList(FormField(AttMarkForm)) button_save = SubmitField('Сохранить') button_clear = SubmitField('Очистить данные ведомости')
class LocationForm(ModelForm): class Meta: model = self.Location addresses = ModelFieldList(FormField(AddressForm))