-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforms.py
68 lines (62 loc) · 2.27 KB
/
forms.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from flask_wtf import FlaskForm
from wtforms import (
StringField,
FloatField,
FieldList,
validators,
BooleanField,
TextAreaField,
)
from wtforms.validators import DataRequired
class StripWhitespaceForm(FlaskForm):
class Meta:
def bind_field(self, form, unbound_field, options):
filters = unbound_field.kwargs.get("filters", [])
if unbound_field.field_class is not FieldList:
filters.append(strip_whitespace)
return unbound_field.bind(form=form, filters=filters, **options)
def strip_whitespace(value):
if value is not None and hasattr(value, "strip"):
return value.strip()
return value
class SignupForm(StripWhitespaceForm):
email = StringField("Email", [validators.Email(), validators.DataRequired()])
password = StringField("password", validators=[DataRequired()])
title = FieldList(
StringField("Title", [validators.DataRequired()]), min_entries=1
) # noqa: E501
company_name = StringField("Company Name")
slogan = StringField("Slogan")
instant_payment = FieldList(
BooleanField("Up-Front Payment", default=False), min_entries=1
)
uuid = FieldList(StringField(), min_entries=1)
subscription = FieldList(
BooleanField("Subscription", default=False), min_entries=1
) # noqa: E501
note_to_seller_required = FieldList(
BooleanField("Require note from customer", default=False),
min_entries=1, # noqa: E501
)
# Allow seller to say what additional information they need
note_to_buyer_message = FieldList(
TextAreaField(
u"Note to buyer",
[validators.optional(), validators.length(max=500)], # noqa: E501
)
)
days_before_first_charge = FieldList(
StringField("Days before first charge")
) # noqa: E501
sell_price = FieldList(
FloatField("Up-front Price", [validators.optional()]), min_entries=1
)
interval_amount = FieldList(
FloatField("Reccuring Amount", [validators.optional()]), min_entries=1
)
interval_unit = FieldList(
StringField("Interval Unit", [validators.optional()]), min_entries=1
)
description = FieldList(
StringField("Interval Unit", [validators.optional()]), min_entries=1
)