Source code for feriennet.forms.match
from onegov.activity.matching.score import PreferAdminChildren
from onegov.activity.matching.score import PreferOrganiserChildren
from onegov.activity.matching.score import PreferGroups
from onegov.activity.matching.score import Scoring
from onegov.feriennet import _
from onegov.form import Form
from wtforms.fields import BooleanField, RadioField
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from sqlalchemy.orm import Session
[docs]
class MatchForm(Form):
[docs]
prefer_organiser = BooleanField(
label=_('Children of organisers'),
fieldset=_('Prefer the following children:'),
default=False)
[docs]
prefer_admins = BooleanField(
label=_('Children of administrators'),
fieldset=_('Prefer the following children:'),
default=False)
[docs]
confirm = RadioField(
label=_('Confirm matching:'),
default='no',
choices=[
('no', _('No, preview only')),
('yes', _('Yes, confirm matching'))
]
)
[docs]
sure = BooleanField(
label=_('I know the wishlist-phase ends as a result.'),
default=False,
depends_on=('confirm', 'yes')
)
[docs]
def scoring(self, session: 'Session') -> Scoring:
scoring = Scoring()
# always prefer groups
scoring.criteria.append(PreferGroups.from_session(session))
if self.prefer_organiser.data:
scoring.criteria.append(
PreferOrganiserChildren.from_session(session))
if self.prefer_admins.data:
scoring.criteria.append(
PreferAdminChildren.from_session(session))
return scoring
@property
[docs]
def confirm_period(self) -> bool:
return self.confirm.data == 'yes' and self.sure.data is True
[docs]
def process_scoring(self, scoring: Scoring) -> None:
classes = {criterium.__class__ for criterium in scoring.criteria}
self.prefer_organiser.data = PreferOrganiserChildren in classes
self.prefer_admins.data = PreferAdminChildren in classes