theraPy/forms/SearchForm.py
2024-08-26 21:05:34 +02:00

29 lines
1.4 KiB
Python

from wtforms import Form, StringField, validators
from wtforms.fields.choices import SelectMultipleField, RadioField
from wtforms.widgets.core import CheckboxInput, ListWidget
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.")
class SearchForm(Form):
location = StringField("Standort", validators=[validators.InputRequired(), validators.Length(min=2, max=50),
validators.Regexp("^[a-zA-ZäöüßÄÖÜẞ]+$")])
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"])])