xppl/app/forms.py

35 lines
1.5 KiB
Python
Raw Normal View History

2018-05-20 00:10:01 +02:00
from flask_wtf import FlaskForm
2018-05-31 20:06:13 +02:00
from wtforms import StringField, FileField, validators
2018-05-23 14:12:24 +02:00
from wtforms.validators import InputRequired, DataRequired
from wtforms import FieldList
from wtforms import Form as NoCsrfForm
from wtforms.fields import StringField, FormField, SubmitField, SelectField
2018-05-23 14:12:24 +02:00
from app.models import Book, BookSchema, Author
# - - - Forms - - -
class AuthorForm(NoCsrfForm):
# this forms is never exposed so we can user the non CSRF version
author_name = StringField('Author Name', validators=[DataRequired()])
2018-05-20 00:10:01 +02:00
2018-05-31 18:26:22 +02:00
class UploadForm(FlaskForm):
2018-05-20 00:10:01 +02:00
title = StringField('title', validators=[InputRequired()])
2018-05-23 14:12:24 +02:00
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
2018-05-27 22:11:35 +02:00
category = StringField('category', validators=[InputRequired()])
year_published = StringField('year published', [validators.Length(max=4)],default=None)
2018-05-20 00:10:01 +02:00
file = FileField()
2018-05-31 18:26:22 +02:00
upload = SubmitField(label='Upload')
wish = SubmitField(label='''I don't have the file, but wish I did.''')
2018-05-23 14:12:24 +02:00
2018-05-31 18:26:22 +02:00
class EditForm(FlaskForm):
2018-05-23 14:12:24 +02:00
title = StringField('title', validators=[InputRequired()])
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
2018-05-27 22:11:35 +02:00
category = StringField('category', validators=[InputRequired()])
year_published = StringField('year published', [validators.Length(max=4)],default=None)
2018-05-31 18:26:22 +02:00
class SearchForm(FlaskForm):
choices = [('Title', 'Title'),
('Category', 'Category')]
select = SelectField('', choices=choices)
2018-05-31 18:26:22 +02:00
search = StringField('', validators=[InputRequired()])