class F(Form): search = html5.SearchField() telephone = html5.TelField() url = html5.URLField() email = html5.EmailField() datetime = html5.DateTimeField() date = html5.DateField() dt_local = html5.DateTimeLocalField() integer = html5.IntegerField() decimal = html5.DecimalField() int_range = html5.IntegerRangeField() decimal_range = html5.DecimalRangeField()
def construct_form(meta): subfs = OrderedDict() for field in meta: kind = field['kind'] name = field['name'] label = field['label'] required = field['required'] checkers = [] if required: if kind == 'int': checkers.append(validators.InputRequired('这个字段必填')) else: checkers.append(validators.Required('这个字段必填')) else: checkers.append(validators.Optional()) if kind == 'int': f = html5.IntegerField(label, description='输入' + label, validators=checkers) elif kind == 'bool': f = fields.BooleanField(label, description=label, validators=[validators.Optional()]) elif kind == 'string': f = fields.StringField(label, description='输入' + label, validators=checkers) elif kind == 'url': checkers.append(validators.URL()) f = html5.URLField(label, description='输入' + label, validators=checkers) else: raise NotImplementedError('%s kind not supported' % kind) subfs[name] = f subform_class = type(b'_Registry_Sub_Form', (WTForm, ), subfs) value_field = fields.FieldList(fields.FormField(subform_class), default=[{}]) form_class = type(b'_Registry_Form', (Form, ), OrderedDict(value=value_field)) return form_class
class datasetForm(FlaskForm): title = f.StringField('Name of this dataset', [ v.InputRequired(r('dataset name')), v.length(5, 250, 'Dataset title must be between 5 and 250 characters long') ]) description = f.TextAreaField('Dataset description', [ v.length( max=65500, message='Description can not be longer than 65,500 characters.') ]) files = f.FieldList(f.FileField('Custom dataset file from your computer'), max_entries=100) newFile = f.SubmitField('Add a new dataset file from your computer', render_kw=w3Button) removeFile = f.SubmitField('Remove the last dataset file entry', render_kw=w3Button) URLs = f.FieldList(f5.URLField('URL of dataset of file', [v.URL('Please enter a valid URL')]), max_entries=100) newURL = f.SubmitField('Add a new dataset URL', render_kw=w3Button) removeURL = f.SubmitField('Remove the last URL entry', render_kw=w3Button) uploadDataset = f.SubmitField('Upload the dataset', render_kw=w3Button)
class WalkForm(Form): title = StringField("Walking Route Title", validators=[InputRequired(), Length(min=5, max=40)], render_kw={ "class": "form-control", "placeholder": "Enter your route title here", "minlength": "5", "maxlength": "40" }) difficulty = SelectField("Difficulty", validators=[InputRequired()], choices=[("", "Select Difficulty")], render_kw={"class": "form-control"}) category_name = SelectField("Walk type", validators=[InputRequired()], choices=[("", "Select Category")], render_kw={"class": "form-control"}) imageUrl = html5.URLField( "Image Url/Address", validators=[InputRequired(), Length(min=20, max=250), URL()], render_kw={ "class": "form-control", "placeholder": ("Please paste a copied web address" "/url for the walk's main image"), "minlength": "20", "maxlength": "250", # regex simulated at https://www.regextester.com/20 "pattern": ("^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)" "([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$") }) description = StringField( "Description", validators=[InputRequired(), Length(min=20, max=200)], render_kw={ "class": "form-control", "placeholder": "Enter a brief description of the walk and area", "minlength": "20", "maxlength": "200" }) time = StringField("Time", validators=[InputRequired(), Length(max=20)], render_kw={ "class": "form-control", "placeholder": "Enter time estimate", "maxlength": "20" }) startpoint = StringField( "Start Point", validators=[InputRequired(), Length(min=5, max=40)], render_kw={ "class": "form-control", "placeholder": "Starting landmark or address", "minlength": "5", "maxlength": "40" }) distance = StringField("Distance", validators=[InputRequired(), Length(max=10)], render_kw={ "class": "form-control", "placeholder": "Enter miles or kilometres", "maxlength": "10" }) dogs_allowed = BooleanField("Dog Friendly", render_kw={"class": "custom-control-input"}) free_parking = BooleanField("Free Parking", render_kw={"class": "custom-control-input"}) paid_parking = BooleanField("Paid Parking", render_kw={"class": "custom-control-input"}) directions = TextAreaField( "Enter your Directions", validators=[InputRequired(), Length(min=100, max=5000)], render_kw={ "class": "form-control", "placeholder": ("Please enter your directions here.\r" "Next instruction on a new line without" " any spaces.\rAnd so on and so forth."), "minlength": "100", "maxlength": "5000", "rows": "10" })
class quickWatchForm(Form): # https://wtforms.readthedocs.io/en/2.3.x/fields/#module-wtforms.fields.html5 # `require_tld` = False is needed even for the test harness "http://localhost:5005.." to run url = html5.URLField('URL', [validators.URL(require_tld=False)]) tag = StringField('Tag', [validators.Optional(), validators.Length(max=35)])