class ArtistForm(FlaskForm): name = StringField("name", validators=[DataRequired()]) city = StringField("city", validators=[DataRequired()]) state = SelectField("state", validators=[DataRequired()], choices=State.choices()) phone = StringField( "phone", validators=[ # DataRequired(), Regexp("^[0-9]*$", message="Phone number should only contain digits"), ], ) image_link = StringField("image_link") genres = SelectMultipleField("genres", validators=[DataRequired()], choices=Genre.choices()) facebook_link = StringField("facebook_link", validators=[URL()]) website = StringField("website", validators=[URL()]) seeking_venue = BooleanField("seeking_venue") seeking_description = StringField("seeking_description") def validate(self): """Define a custom validate method in your Form:""" rv = FlaskForm.validate(self) if not rv: return False if not set(self.genres.data).issubset(dict(Genre.choices()).keys()): self.genres.errors.append("Invalid genre.") return False if self.state.data not in dict(State.choices()).keys(): self.state.errors.append("Invalid state.") return False # if pass validation return True
class VenueForm(Form): name = StringField( 'name', validators=[DataRequired()] ) city = StringField( 'city', validators=[DataRequired()] ) state = SelectField( 'state', validators=[DataRequired()], choices=State.choices() ) address = StringField( 'address', validators=[DataRequired()] ) phone = StringField( 'phone' , validators=[DataRequired(), Length(min=10, max=11) ] ) image_link = StringField( 'image_link' ) genres = SelectMultipleField( # TODO implement enum restriction 'genres', choices=Genre.choices() ) facebook_link = StringField( 'facebook_link', validators=[URL()] ) website = StringField( 'website', validators=[URL()] ) seeking_talent = SelectField('seeking_talent', choices=[(False, 'No'), (True, 'Yes')]) seeking_description = StringField( 'seeking_description', validators=[DataRequired()] )
def validate(self): """Define a custom validate method in your Form:""" rv = FlaskForm.validate(self) if not rv: return False if self.state.data not in dict(State.choices()).keys(): self.state.errors.append('Invalid state.') return False if not set(self.genres.data).issubset(dict(Genre.choices()).keys()): self.genres.errors.append('Invalid genres.') return False if not is_valid_phone(self.phone.data): self.phone.errors.append('Invalid phone format.') return False if not is_website_valid(self.website.data): self.website.errors.append('Invalid website url') return False if not is_facebook_valid(self.facebook_link.data): self.facebook_link.errors.append('Invalid Facebook url') return False return True
class VenueForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[DataRequired()], choices=State.choices()) address = StringField('address', validators=[DataRequired()]) phone = StringField( 'phone', validators=[ DataRequired(), Regexp('^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$') ]) image_link = StringField('image_link', validators=[URL()]) genres = SelectMultipleField( # TODO implement enum restriction 'genres', validators=[DataRequired()], choices=Genre.choices()) facebook_link = StringField('facebook_link', validators=[URL()]) seeking_talent = BooleanField('seeking_talent', default=False) seeking_description = StringField('seeking_description') website = StringField( # TODO implement enum restriction 'website', validators=[URL()]) def validate(self): # """Define a custom validate method in your Form:""" rv = Form.validate(self) if not rv: return False if not set(self.genres.data).issubset(dict(Genre.choices()).keys()): self.genres.errors.append('Invalid genre.') return False if self.state.data not in dict(State.choices()).keys(): self.state.errors.append('Invalid state.') return False # if pass validation return True
class VenueForm(Form): def validate_phone(self, phone): if not re.search(r"^[0-9]{3}-[0-9]{3}-[0-9]{4}$", field.data): raise ValidationError("Invalid phone number.") def validate_genres(self, genres): genres_values = [choice[1] for choice in genres_choices] for value in field.data: if value not in genres_values: raise ValidationError('Invalid genres value.') name = StringField('name', validators=[DataRequired(), Length(-1, 120)]) city = StringField('city', validators=[DataRequired(), Length(-1, 120)]) state = SelectField( 'state', validators=[DataRequired(), AnyOf([choice.value for choice in State])], choices=State.choices()) address = StringField('address', validators=[DataRequired(), Length(-1, 120)]) # IDEA: add a phone number validator phone = StringField('phone', validators=[DataRequired()]) image_link = StringField('image_link', validators=[Length(-1, 500), URL(), Optional()]) genres = SelectMultipleField('genres', validators=[ DataRequired(), anyof_for_multiple_field( [choice.value for choice in Genre]) ], choices=Genre.choices()) facebook_link = StringField( 'facebook_link', validators=[Length(-1, 120), URL(), Optional()])
class ArtistForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[DataRequired()], choices=State.choices()) phone = StringField('phone') image_link = StringField('image_link') genres = SelectMultipleField('genres', validators=[ DataRequired(), AnyOf([(choice.value) for choice in Genre]) ], choices=Genre.choices()) facebook_link = StringField('facebook_link', validators=[URL()]) website_link = StringField('website_link') seeking_venue = BooleanField('seeking_venue') seeking_description = StringField('seeking_description')
class VenueForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[DataRequired()], choices=State.choices()) try: genres_choices = [(genre.name, genre.name) for genre in Genre.query.all()] except: genres_choices = [] address = StringField('address', validators=[DataRequired()]) phone = StringField('phone') seeking_talent = BooleanField('seeking_talent') seeking_description = StringField('seeking_description') web_link = StringField('web_link', validators=[URL()]) image_link = StringField('image_link', validators=[URL()]) genres = SelectMultipleGenresField( # implement enum restriction 'genres', validators=[DataRequired()], choices=genres_choices) facebook_link = StringField('facebook_link', validators=[URL()])
class VenueForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[ DataRequired(), AnyOf([(choice.value) for choice in State]) ], choices=State.choices()) address = StringField('address', validators=[DataRequired()]) phone = StringField('phone', validators=[DataRequired()]) image_link = StringField('image_link') genres = SelectMultipleField('genres', validators=[ DataRequired(), AnyOf([(choice.value) for choice in Genre]) ], choices=Genre.choices()) facebook_link = StringField('facebook_link', validators=[URL()]) website_link = StringField('website_link') seeking_artists = SelectField('seeking_artists', validators=[DataRequired()], choices=[ ('True', 'Yes'), ('False', 'No'), ]) seeking_description = StringField('seeking_description', validators=[DataRequired()])
class VenueForm(Form): name = StringField( 'Venue name', validators=[DataRequired(message='Please enter a venue name'), Length(min=2, max=50)] ) city = StringField( 'City', validators=[DataRequired('Please enter the venue\'s city'), Length(min=2, max=50)] ) state = SelectField( 'State', validators=[DataRequired(message='Please select the venue\'s state'), Length(min=2, max=50), AnyOf([choice.value for choice in State])], choices=State.choices() ) address = StringField( 'Address', validators=[DataRequired(message='Please enter the venue\'s address'), Length(min=10, max=120)] ) phone = StringField( 'Phone Number' ) image_link = StringField( 'Image link' ) genres = SelectMultipleField( 'Genres', validators=[DataRequired(), Length(max=150), ValidateValues([choice.value for choice in Genre])], choices=Genre.choices() ) website = StringField( 'Website', validators=[optional(strip_whitespace=False), URL(message='Please enter a valid URL'), Length(min=10, max=120)] ) facebook_link = StringField( 'Facebook link', validators=[optional(strip_whitespace=False), URL(message='Please enter a valid URL'), Length(min=15, max=120)] ) seeking_talent = BooleanField( 'Looking for artists' ) seeking_description = TextAreaField( 'Description for artists', validators=[Length(max=500)] )
class BaseForm(FlaskForm): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[DataRequired()], choices=State.choices()) image_link = StringField('image_link', validators=[DataRequired(), URL()]) seeking_description = TextAreaField( 'seeking_description', validators=[Optional()] # it can be empty ) genres_ids = SelectMultipleField( 'genres', validators=[DataRequired()], # make sure to run migration with flask db upgrade # as it will add initial data to genres table choices=[], ) def __init__(self, **kwargs): super().__init__(**kwargs) # Need to set it on every init as it's not constant # For this case actually it's constant but it's good for future self.genres_ids.choices = Genre.genres_choices()
class ArtistForm(Form): name = StringField('name', validators=[DataRequired(), Length(-1, 120)]) city = StringField('city', validators=[DataRequired(), Length(-1, 120)]) state = SelectField( 'state', validators=[DataRequired(), AnyOf([choice.value for choice in State])], choices=State.choices()) # IDEA: add a phone number validator phone = StringField('phone') image_link = StringField('image_link', validators=[Length(-1, 500), URL(), Optional()]) genres = SelectMultipleField('genres', validators=[ DataRequired(), anyof_for_multiple_field( [choice.value for choice in Genre]) ], choices=Genre.choices()) facebook_link = StringField( 'facebook_link', validators=[Length(-1, 120), URL(), Optional()])
class ArtistForm(Form): def validate(self): """Define a custom validate method in your Form:""" rv = Form.validate(self) if not rv: return False if not is_valid_phone(self.phone.data): self.phone.errors.append(':: Invalid phone number:') return False if not set(self.genres.data).issubset(dict(Genre.choices()).keys()): self.genres.errors.append(':: Invalid genres.') return False if self.state.data not in dict(State.choices()).keys(): self.state.errors.append(':: Invalid state.') return False # if pass validation return True name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[DataRequired()], choices=State.choices()) phone = StringField('phone') image_link = StringField('image_link') genres = SelectMultipleField('genres', validators=[DataRequired()], choices=Genre.choices()) facebook_link = StringField('facebook_link', validators=[URL()]) website_link = StringField('website_link') seeking_venue = BooleanField('seeking_venue') seeking_description = StringField('seeking_description')
def is_valid_state(form, field): if field.data not in dict(State.choices()).keys(): raise ValidationError('Invalid state.')