xppl/app/forms.py

51 lines
2.2 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-06-03 14:01:59 +02:00
from app.models import Book, BookSchema, Author, Stack, StackSchema
2018-05-23 14:12:24 +02:00
# - - - 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-06-05 18:26:25 +02:00
2018-06-03 12:29:08 +02:00
class ChatForm(FlaskForm):
message = StringField('message', validators=[InputRequired()])
send = SubmitField(label='Send')
2018-06-03 14:01:59 +02:00
class StackForm(FlaskForm):
stack_name = StringField('Stack', validators=[InputRequired()])
stack_description = StringField('Description', validators=[InputRequired()])
create = SubmitField(label='Create')
2018-05-31 18:26:22 +02:00
2018-06-03 23:33:16 +02:00
class AddtoStackForm(FlaskForm):
2018-06-04 23:40:12 +02:00
select_stack = SelectField('Stacks', validators=[InputRequired()])
2018-06-05 18:26:25 +02:00
class EditStackForm(FlaskForm):
2018-06-06 11:39:38 +02:00
edit_stack_name = StringField('Stack', validators=[InputRequired()])
edit_stack_description = StringField('Description', validators=[InputRequired()])
2018-06-05 18:26:25 +02:00
2018-05-31 18:26:22 +02:00
class SearchForm(FlaskForm):
choices = [('All', 'All'),
('Title', 'Title'),
('Category', 'Category')]
select = SelectField('', choices=choices)
2018-05-31 18:26:22 +02:00
search = StringField('', validators=[InputRequired()])