-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
39 lines (32 loc) · 1.08 KB
/
Copy pathforms.py
File metadata and controls
39 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from wtforms import widgets
from flask_wtf import FlaskForm
from wtforms.fields.core import SelectMultipleField
from wtforms_alchemy import model_form_factory
from models import db, User, Task
# required to have FlaskForm mix with WTForms Alchemy
BaseModelForm = model_form_factory(FlaskForm)
class ModelForm(BaseModelForm):
@classmethod
def get_session(self):
return db.session
# helper custom fields
class MultiCheckboxField(SelectMultipleField):
"""allows for a multiselect field made up of checkboxes"""
widget = widgets.ListWidget(prefix_label=False)
option_widget = widgets.CheckboxInput()
# app forms
class CreateUserForm(ModelForm):
"""form for making users"""
class Meta:
model = User
class LoginUserForm(ModelForm):
"""form for logging in users"""
class Meta:
model = User
only = ["email", "password"]
unique_validator = None
class UserTaskForm(ModelForm):
"""form for creating / editing tasks of users"""
class Meta:
model = Task
freetimes = MultiCheckboxField("Freetimes", coerce=int)