Source code for org.forms.person

from __future__ import annotations

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 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
    from wtforms.fields.choices import _Choice


[docs] class PersonForm(Form): """ Form to edit people. """
[docs] request: OrgRequest
[docs] salutation = StringField(_('Salutation'))
[docs] academic_title = StringField(_('Academic Title'))
[docs] first_name = StringField(_('First name'), [InputRequired()])
[docs] last_name = StringField(_('Last name'), [InputRequired()])
[docs] function = StringField(_('Function'))
[docs] organisations_multiple = ChosenSelectMultipleField( label=_('Organisation'), description=_('Select the organisations this person belongs to'), choices=[], )
[docs] email = EmailField(_('E-Mail'))
[docs] phone = StringField(_('Phone'))
[docs] phone_direct = StringField(_('Direct Phone Number or Mobile'))
[docs] born = StringField(_('Born'))
[docs] profession = StringField(_('Profession'))
[docs] political_party = StringField(_('Political Party'))
[docs] parliamentary_group = StringField(_('Parliamentary Group'))
[docs] website = StringField(_('Website'), filters=(ensure_scheme, ))
[docs] website_2 = StringField(_('Website 2'), filters=(ensure_scheme, ))
[docs] location_address = TextAreaField( label=_('Location address'), render_kw={'rows': 3} )
[docs] location_code_city = StringField(label=_('Location Code and City'))
[docs] postal_address = TextAreaField( label=_('Postal address'), render_kw={'rows': 3} )
[docs] postal_code_city = StringField(label=_('Postal Code and City'))
[docs] picture_url = StringField( label=_('Picture'), description=_('URL pointing to the picture'), render_kw={'class_': 'image-url'} )
[docs] notes = TextAreaField( label=_('Notes'), description=_('Public extra information about this person'), render_kw={'rows': 6} )
[docs] def on_request(self) -> None: choices: list[_Choice] = [] categories, subcategories = extract_categories_and_subcategories( self.request.app.org.organisation_hierarchy) for cat, sub in zip(categories, subcategories): choices.append((cat, cat)) choices.extend((f'-{s}', f'- {s}') for s in sub) if not choices: self.delete_field('organisations_multiple') return self.organisations_multiple.choices = choices