Source code for org.forms.resource_recipient

from onegov.form import Form
from onegov.form.fields import MultiCheckboxField
from import _
from onegov.reservation import Resource, ResourceCollection
from wtforms.fields import EmailField
from wtforms.fields import StringField
from wtforms.fields import BooleanField
from wtforms.validators import InputRequired, Email

from typing import TYPE_CHECKING
    from import OrgRequest

[docs] WEEKDAYS = ( ("MO", _("Mo")), ("TU", _("Tu")), ("WE", _("We")), ("TH", _("Th")), ("FR", _("Fr")), ("SA", _("Sa")), ("SU", _("Su")), )
[docs] class ResourceRecipientForm(Form): if TYPE_CHECKING: request: OrgRequest
[docs] name = StringField( label=_("Name"), fieldset="Empfänger", description="Peter Muster", validators=[InputRequired()] )
[docs] address = EmailField( label=_("E-Mail"), fieldset="Empfänger", description="", validators=[InputRequired(), Email()] )
[docs] new_reservations = BooleanField( label=_("New Reservations"), fieldset=_("Notifications *"), description=_("For each new reservation, a notification will be sent " "to the above recipient."), )
[docs] daily_reservations = BooleanField( label=_("Daily Reservations"), fieldset=_("Notifications *"), description=_("On each day selected below, a notification with the " "day's reservations will be sent to the recipient above " "at 06:00."), )
[docs] internal_notes = BooleanField( label=_("Internal Notes"), fieldset=_("Notifications *"), description=_("Each time a new note is added to the ticket for a " "reservation, a notification is sent to the recipient " "above."), )
[docs] rejected_reservations = BooleanField( label=_("Rejected Reservations"), fieldset=_("Notifications *"), description=_("If a reservation is cancelled, a notification will " "be sent to the above recipient."), )
[docs] send_on = MultiCheckboxField( label=_("Send on"), fieldset="Tage und Ressourcen", choices=WEEKDAYS, default=[key for key, value in WEEKDAYS], validators=[InputRequired()], depends_on=('daily_reservations', 'y'), render_kw={'prefix_label': False, 'class_': 'oneline-checkboxes'} )
[docs] resources = MultiCheckboxField( label=_("Resources"), fieldset="Tage und Ressourcen", validators=[InputRequired()], choices=None )
[docs] def validate(self) -> bool: # type:ignore[override] result = super().validate() if not ( or or or ): assert isinstance(self.daily_reservations.errors, list) self.daily_reservations.errors.append( _("Please add at least one notification.") ) result = False return result
[docs] def on_request(self) -> None: self.populate_resources()
[docs] def populate_resources(self) -> None: q = ResourceCollection( q = q.order_by(, q = q.with_entities(, Resource.title, default_group = self.request.translate(_("General")) self.resources.choices = [ (, f'{ or default_group} - {r.title}') for r in q ]