Source code for org.forms.person
from onegov.core.utils import ensure_scheme
from onegov.form import Form
from onegov.form.fields import ChosenSelectMultipleField
from onegov.org import _
from wtforms.validators import InputRequired
from wtforms.fields import EmailField
from wtforms.fields import SelectChoice
from wtforms.fields import StringField
from wtforms.fields import TextAreaField
from onegov.org.utils import extract_categories_and_subcategories
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from onegov.org.app import OrgRequest
# FIXME: Would a TreeSelectField be better here?
[docs]
def organisations_multiple_choices(
form: PersonForm,
field: ChosenSelectMultipleField
) -> list[SelectChoice]:
categories, subcategories = extract_categories_and_subcategories(
form.request.app.org.organisation_hierarchy)
choices: list[SelectChoice] = []
for cat, sub in zip(categories, subcategories):
choices.append(SelectChoice(cat))
choices.extend(SelectChoice(f'-{s}', f'- {s}') for s in sub)
return choices
[docs]
class PersonForm(Form):
""" Form to edit people. """
[docs]
organisations_multiple = ChosenSelectMultipleField(
label=_('Organisation'),
description=_('Select the organisations this person belongs to'),
choices=organisations_multiple_choices,
)
[docs]
picture_url = StringField(
label=_('Picture'),
description=_('URL pointing to the picture'),
render_kw={
'class_': 'image-url',
'data-initial-aspect-ratio': '1:1',
'data-fixed-aspect-ratio': 'true',
'data-circular': 'true',
}
)
[docs]
notes = TextAreaField(
label=_('Notes'),
description=_('Public extra information about this person'),
render_kw={'rows': 6}
)
[docs]
def on_request(self) -> None:
if not self.organisations_multiple.choices:
self.delete_field('organisations_multiple')