xppl/app/forms.py

86 lines
3.8 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
2018-06-07 23:33:22 +02:00
from wtforms.fields import StringField, FormField, SubmitField, SelectField, RadioField
2018-06-03 14:01:59 +02:00
from app.models import Book, BookSchema, Author, Stack, StackSchema
2018-06-11 12:00:48 +02:00
from wtforms.fields.html5 import DecimalRangeField
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.''')
message = StringField('message', default=None)
2018-06-11 12:00:48 +02:00
sameness = DecimalRangeField('sameness', default=0)
diversity = DecimalRangeField('diversity', default=0)
gender = DecimalRangeField('gender', default=50)
choices = [('Student', 'Student'),
('Librarian', 'Librarian'),
('Pirate', 'Pirate'),
('Teacher', 'Teacher'),
('Institution', 'Institution'),
('All of the above', 'All of the above'),
('None of the above', 'None of the above')]
who = SelectField('', choices=choices, default='Student')
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)
file = FileField()
message = StringField('message')
2018-06-11 17:24:30 +02:00
sameness = DecimalRangeField('sameness', default=0)
diversity = DecimalRangeField('diversity', default=0)
gender = DecimalRangeField('gender', default=50)
choices = [('Student', 'Student'),
('Librarian', 'Librarian'),
('Pirate', 'Pirate'),
('Teacher', 'Teacher'),
('Institution', 'Institution'),
('All of the above', 'All of the above'),
('None of the above', 'None of the above')]
who = SelectField('', choices=choices, default='Student')
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()])
2018-06-10 19:33:50 +02:00
stack_author = StringField('Who made this', validators=[InputRequired()])
2018-06-03 14:01:59 +02:00
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'),
2018-06-07 10:46:14 +02:00
('Author', 'Author'),
('Category', 'Category'),
2018-06-11 18:09:17 +02:00
('Stack', 'Stack'),
('Outliers', 'Outliers')]
2018-06-07 23:33:22 +02:00
select = SelectField('', choices=choices, default='All')
2018-05-31 18:26:22 +02:00
search = StringField('', validators=[InputRequired()])
grid = SubmitField('Grid')
listview = SubmitField('List')
2018-06-07 23:33:22 +02:00
randomize = SubmitField('Order differently')