addform.py 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. from flask_wtf import FlaskForm
  2. from wtforms import SubmitField, StringField, SelectField, TimeField, DateField
  3. from wtforms.validators import DataRequired, URL
  4. class CafeForm(FlaskForm):
  5. cafe = StringField('Cafe name', validators=[DataRequired()])
  6. location = StringField('Location URL', validators=[DataRequired(), URL()])
  7. open = TimeField('Open time', validators=[DataRequired()])
  8. close = TimeField('Closing time', validators=[DataRequired()])
  9. coffee_rating = SelectField(
  10. 'Coffee rating', validators=[DataRequired()],
  11. choices=['☕️', '☕️☕️', '☕️☕️☕️', '☕️☕️☕️☕️', '☕️☕️☕️☕️☕️']
  12. )
  13. wifi_rating = SelectField(
  14. 'Wifi rating', validators=[DataRequired()],
  15. choices=['✘', '💪', '💪💪', '💪💪💪', '💪💪💪💪', '💪💪💪💪💪']
  16. )
  17. power_rating = SelectField(
  18. 'Power rating', validators=[DataRequired()],
  19. choices=['✘', '🔌', '🔌🔌', '🔌🔌🔌', '🔌🔌🔌🔌', '🔌🔌🔌🔌🔌']
  20. )
  21. submit = SubmitField('Submit')
  22. # Exercise:
  23. # add: Location URL, open time, closing time, coffee rating, wifi rating, power outlet rating fields
  24. # make coffee/wifi/power a select element with choice of 0 to 5.
  25. #e.g. You could use emojis ☕️/💪/✘/🔌
  26. # make all fields required except submit
  27. # use a validator to check that the URL field has a URL entered.
  28. # ---------------------------------------------------------------------------