Source code for activity.collections.volunteer

from onegov.activity.models import Volunteer
from onegov.core.collection import GenericCollection
from onegov.core.orm.sql import as_selectable_from_path
from onegov.core.utils import module_path
from sqlalchemy import select


from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from collections.abc import Sequence
    from datetime import date, datetime
    from onegov.activity.models import Period, PeriodMeta
    from onegov.activity.models.volunteer import VolunteerState
    from sqlalchemy.orm import Query, Session
    from uuid import UUID
    from typing import NamedTuple
    from typing import Self, TypeAlias

[docs] class ReportRowWithVolunteer(NamedTuple):
[docs] activity_id: UUID
[docs] activity_title: str
[docs] activity_name: str
[docs] need_id: UUID
[docs] need_name: str
[docs] min_required: int
[docs] max_required: int
[docs] confirmed: int
[docs] occasion_id: UUID
[docs] period_id: UUID
[docs] occasion_number: int
[docs] volunteer_id: UUID
[docs] first_name: str
[docs] last_name: str
[docs] address: str
[docs] zip_code: str
[docs] place: str
[docs] organisation: str | None
[docs] birth_date: date
[docs] age: int
[docs] email: str
[docs] phone: str
[docs] state: VolunteerState
[docs] dates: Sequence[datetime]
class ReportRowWithoutVolunteer(NamedTuple): activity_id: UUID activity_title: str activity_name: str need_id: UUID need_name: str min_required: int max_required: int confirmed: int occasion_id: UUID period_id: UUID occasion_number: int volunteer_id: None first_name: None last_name: None address: None zip_code: None place: None organisation: None birth_date: None age: None email: None phone: None state: None dates: Sequence[datetime] ReportRow: TypeAlias = ReportRowWithVolunteer | ReportRowWithoutVolunteer
[docs] class VolunteerCollection(GenericCollection[Volunteer]): def __init__( self, session: 'Session', period: 'Period | PeriodMeta | None' ) -> None: super().__init__(session)
[docs] self.period = period
@property
[docs] def model_class(self) -> type[Volunteer]: return Volunteer
@property
[docs] def period_id(self) -> 'UUID | None': return self.period and self.period.id or None
[docs] def report(self) -> 'Query[ReportRow]': stmt = as_selectable_from_path( module_path('onegov.activity', 'queries/volunteer-report.sql')) query = select(stmt.c).where(stmt.c.period_id == self.period_id) return self.session.execute(query)
[docs] def for_period(self, period: 'Period | PeriodMeta | None') -> 'Self': return self.__class__(self.session, period)