Files
@ 401cab1bcd6c
Branch filter:
Location: C3L/C3L-Membership-Online-Form/c3l_membership/forms.py - annotation
401cab1bcd6c
4.5 KiB
text/x-python
Begin typing annotations
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | 401cab1bcd6c 401cab1bcd6c 805cb46ada9a 7cf7d1e162a4 262323080d4e 262323080d4e 262323080d4e 401cab1bcd6c 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 7cf7d1e162a4 6f06fc328a13 6f06fc328a13 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 401cab1bcd6c 262323080d4e 262323080d4e 262323080d4e 401cab1bcd6c 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 7cf7d1e162a4 6f06fc328a13 6f06fc328a13 805cb46ada9a 805cb46ada9a 805cb46ada9a 805cb46ada9a 805cb46ada9a 6f06fc328a13 9b37bb918b8a 6f06fc328a13 805cb46ada9a 805cb46ada9a 6f06fc328a13 9b37bb918b8a 6f06fc328a13 805cb46ada9a 805cb46ada9a 805cb46ada9a 805cb46ada9a 805cb46ada9a 6f06fc328a13 6f06fc328a13 6f06fc328a13 805cb46ada9a 805cb46ada9a 6f06fc328a13 52127f437376 52127f437376 805cb46ada9a 805cb46ada9a 805cb46ada9a 52127f437376 6f06fc328a13 6f06fc328a13 805cb46ada9a 805cb46ada9a 805cb46ada9a 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 52127f437376 805cb46ada9a 805cb46ada9a 805cb46ada9a 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 262323080d4e 52127f437376 52127f437376 52127f437376 805cb46ada9a 52127f437376 52127f437376 52127f437376 52127f437376 6f06fc328a13 805cb46ada9a 805cb46ada9a 6f06fc328a13 6f06fc328a13 68ea3e6dd3a6 9954f35f0971 6f06fc328a13 805cb46ada9a 3e495ae230a2 6f06fc328a13 9b37bb918b8a c4c5ab9a2bb8 805cb46ada9a 3e495ae230a2 6f06fc328a13 6f06fc328a13 6f06fc328a13 805cb46ada9a 3e495ae230a2 6f06fc328a13 6f06fc328a13 6f06fc328a13 805cb46ada9a 3e495ae230a2 6f06fc328a13 6f06fc328a13 6f06fc328a13 805cb46ada9a 3e495ae230a2 6f06fc328a13 6f06fc328a13 6f06fc328a13 805cb46ada9a 43a5d40b28e0 6f06fc328a13 6f06fc328a13 6f06fc328a13 6f06fc328a13 805cb46ada9a | from typing import Optional as tOptional
from flask_babel import lazy_gettext
from flask_wtf import FlaskForm
from wtforms import (
BooleanField,
DateField,
Field,
RadioField,
StringField,
SubmitField,
ValidationError,
)
from wtforms.validators import Email, InputRequired, Length, Optional
class NotEqualTo:
"""
Compares the values of two fields.
:param fieldname:
The name of the other field to compare to.
:param message:
Error message to raise in case of a validation error. Can be
interpolated with `%(other_label)s` and `%(other_name)s` to provide a
more helpful error.
"""
def __init__(self, fieldname: str, message: tOptional[str] = None) -> None:
self.fieldname = fieldname
self.message = message
def __call__(self, form: FlaskForm, field: Field) -> None:
try:
other = form[self.fieldname]
except KeyError as exc:
raise ValidationError(
field.gettext("Invalid field name '%s'.") % self.fieldname
) from exc
if field.data != other.data:
return
d = {
"other_label": hasattr(other, "label")
and other.label.text
or self.fieldname,
"other_name": self.fieldname,
}
message = self.message
if message is None:
message = field.gettext("Field must not be equal to %(other_name)s.")
raise ValidationError(message % d)
class MembershipForm(FlaskForm):
username = StringField(
lazy_gettext("Username"),
validators=[
InputRequired(lazy_gettext("This field is required!")),
Length(max=255),
],
)
email = StringField(
lazy_gettext("E-Mail"),
validators=[InputRequired(lazy_gettext("This field is required!")), Email()],
)
fullname = StringField(
lazy_gettext("Full Name"),
validators=[
InputRequired(lazy_gettext("This field is required!")),
Length(max=65536),
],
)
membership = RadioField(
lazy_gettext("Membership Plan"),
validators=[InputRequired(lazy_gettext("Please select one of the options!"))],
choices=[
(
"regular",
lazy_gettext(
"Regular membership - Membership with voting rights on the general assembly."
),
),
(
"supporting",
lazy_gettext(
"Supporting membership - Membership without voting rights on the general assembly."
),
),
],
)
student = BooleanField(
lazy_gettext(
"I am a student and would like to have the reduced membership fees."
),
validators=[
Optional(),
NotEqualTo(
"starving",
lazy_gettext(
"Student and Starving Hacker are mutually exclusive! Please select only one of them."
),
),
],
)
starving = BooleanField(
lazy_gettext(
"I am a starving hacker and cannot afford the membership! (Please get in touch with us at info@c3l.lu before filling out this membership form)"
)
)
payment = RadioField(
lazy_gettext("Payment Options"),
validators=[InputRequired(lazy_gettext("Please select one of the options!"))],
)
birthday = DateField(lazy_gettext("Birthday"), validators=[InputRequired()])
street = StringField(
lazy_gettext("Nr., Street"),
validators=[Optional(), Length(max=4000)],
)
postal = StringField(
lazy_gettext("Postal Code"),
validators=[Optional(), Length(max=30)],
)
city = StringField(
lazy_gettext("City/Town"),
validators=[Optional(), Length(max=500)],
)
state = StringField(
lazy_gettext("State/County/Province"),
validators=[Optional(), Length(max=500)],
)
country = StringField(
lazy_gettext("Country"),
validators=[Optional(), Length(max=500)],
)
terms = BooleanField(
lazy_gettext(
'By submitting this membership application, you agree to have read and understood the <a href="http://statutes.c3l.lu">statutes of the Chaos Computer Club Lëtzebuerg A.S.B.L.</a>.'
),
validators=[InputRequired()],
)
submit = SubmitField(lazy_gettext("Become a member"))
|