52 lines
2.3 KiB
Python
52 lines
2.3 KiB
Python
from wtforms import Form, StringField, validators
|
|
from wtforms.fields.choices import SelectMultipleField, RadioField
|
|
from wtforms.fields.numeric import IntegerField
|
|
from wtforms.widgets.core import CheckboxInput, ListWidget, Input
|
|
|
|
|
|
def validate_therapy_types(form, field):
|
|
valid_choices = {"A", "S", "T", "V"}
|
|
if not all(choice in valid_choices for choice in field.data):
|
|
raise validators.ValidationError("Invalid value in therapy types selection.")
|
|
|
|
|
|
def validate_therapy_phone_times(form, field):
|
|
valid_choices = {1, 2, 3, 4}
|
|
if not field.data:
|
|
raise validators.ValidationError("Please select at least one option.")
|
|
if not all(choice in valid_choices for choice in field.data):
|
|
raise validators.ValidationError("Invalid value in therapy phone types selection.")
|
|
|
|
|
|
class RangeInput(Input):
|
|
input_type = "range"
|
|
|
|
|
|
class SearchForm(Form):
|
|
location = StringField("Standort/PLZ", validators=[validators.InputRequired(), validators.Length(min=2, max=50),
|
|
validators.Regexp("^[a-zA-ZäöüßÄÖÜẞ]+$")])
|
|
therapy_distance = IntegerField(
|
|
"Distanz (in km)",
|
|
widget=RangeInput(),
|
|
default=25,
|
|
validators=[validators.InputRequired(), validators.NumberRange(min=0, max=50)]
|
|
)
|
|
therapy_type = SelectMultipleField("Therapieverfahren", choices=[
|
|
("A", "Analytische Psychotherapie"),
|
|
("S", "Systemische Therapie"),
|
|
("T", "Tiefenpsychologisch fundierte Psychotherapie"),
|
|
("V", "Verhaltenstherapie")], option_widget=CheckboxInput(), widget=ListWidget(prefix_label=False),
|
|
validators=[validate_therapy_types])
|
|
therapy_age_range = RadioField("Altersgruppe", choices=[
|
|
("E", "Erwachsene"),
|
|
("K", "Kinder und Jugendliche")], validators=[validators.InputRequired(), validators.any_of(["E", "K"])])
|
|
therapy_setting = RadioField("Therapiesetting", choices=[
|
|
("E", "Einzeltherapie"),
|
|
("G", "Gruppentherapie")], validators=[validators.InputRequired(), validators.any_of(["E", "G"])])
|
|
# TODO: find a better name for label
|
|
amount_of_weeks = IntegerField(
|
|
"Telefonzeiten für die nächsten Wochen",
|
|
widget=RangeInput(),
|
|
default=1,
|
|
validators=[validators.InputRequired(), validators.NumberRange(min=1, max=4)]
|
|
) |