def _phone(form, field): data = field.data if not (len(data) == 10): raise ValidationError phone_number = parse(data, "US") city, state = geocoder.description_for_number(phone_number, "en").split(', ') # Checks for states in enum if not (state in [value for choice, value in States.choices()]): raise ValidationError
class VenueForm(FlaskForm): name = StringField("name", [DataRequired(), Length(1, 120)]) city = StringField("city", [DataRequired(), Length(1, 120)]) state = SelectField( "state", [DataRequired()], choices=States.choices(), ) address = StringField("address", [DataRequired(), Length(1, 120)]) phone = StringField("phone", [Length(10, 15), Optional()]) image_link = StringField("image_link", [Length(1, 500), URL(), Optional()]) genres = SelectMultipleField( "genres", [DataRequired()], choices=Genres.choices(), ) facebook_link = StringField("facebook_link", [URL(), Optional()])
class VenueForm(Form): name = StringField( 'name', validators=[DataRequired()] ) city = StringField( 'city', validators=[DataRequired()] ) state = SelectField( 'state', validators=[ DataRequired(), AnyOf([choice.value for choice in States]) ], choices=States.choices() ) address = StringField( 'address', validators=[DataRequired()] ) phone = StringField( 'phone', validators=[DataRequired(), is_valid_phone] ) genres = SelectMultipleField( 'genres', validators=[ DataRequired(), multiple_field_validation([choice.value for choice in Genres]) ], choices=Genres.choices() ) website = StringField( 'website', validators=[DataRequired(), URL()] ) image_link = StringField( 'image_link', validators=[DataRequired(), URL()] ) facebook_link = StringField( 'facebook_link', validators=[DataRequired(), URL()] ) seeking_talent = BooleanField( 'seeking_talent' ) seeking_description = StringField( 'seeking_description' )
class VenueForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[ DataRequired(), AnyOf([choice.value for choice in States]) ], choices=States.choices()) address = StringField('address', validators=[DataRequired()]) phone = StringField('phone', validators=[phone()]) genres = SelectMultipleField( # TODO:[COMPLETED] implement enum restriction 'genres', validators=[DataRequired(), my_genres()], choices=Genre.choices()) facebook_link = StringField('facebook_link', validators=[fb_url()]) image_link = StringField('image_link', validators=[my_url()]) website = StringField('website', validators=[my_url()]) seeking_talent = BooleanField('seeking_talent', default="checked") seeking_description = StringField('seeking_description', validators=[Length(max=256)])
class EntityForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', default=States.AL, validators=[DataRequired()], choices=States.choices(), coerce=States.coerce) phone = StringField('phone') def validate_phone(form, field): print('validating phone') data = field.data if (data is not None): phone_number = data.replace('-', '') print(phone_number) if len(phone_number) != 10: raise ValidationError( "Phone number must be of the formation XXX-XXX-XXXX") else: pattern = re.compile("^[\d]{10}$") if (pattern.match(phone_number) is None): raise ValidationError( "Phone number must be of the formation XXX-XXX-XXXX") genres = SelectMultipleField('genres', validators=[DataRequired()], choices=Genres.choices(), coerce=Genres.coerce) facebook_link = StringField('facebook_link', validators=[URL()]) image_link = StringField('image_link', validators=[URL()]) website = StringField('website', validators=[URL()]) seeking_description = TextAreaField('seeking_description')
class ArtistForm(Form): name = StringField('name', validators=[DataRequired()]) city = StringField('city', validators=[DataRequired()]) state = SelectField('state', validators=[DataRequired()], choices=States.choices()) phone = StringField( # TODO:[COMPLETED] implement validation logic for state 'phone', validators=[phone()]) image_link = StringField('image_link', validators=[my_url()]) genres = SelectMultipleField( # TODO;[COMPLETED] implement enum restriction 'genres', validators=[DataRequired(), my_genres()], choices=Genre.choices()) facebook_link = StringField( # TODO:[COMPLETED] implement enum restriction 'facebook_link', validators=[fb_url()]) website = StringField('website', validators=[my_url()]) seeking_venue = BooleanField('seeking_venue', default="checked") seeking_description = StringField('seeking_description', validators=[Length(max=256)])