from __future__ import annotations
from datetime import date
from onegov.core.orm import Base
from onegov.core.orm.mixins import ContentMixin, TimestampMixin
from sqlalchemy import Enum, ForeignKey
from sqlalchemy.orm import mapped_column, relationship, Mapped
from uuid import uuid4, UUID
from typing import Literal, TYPE_CHECKING
if TYPE_CHECKING:
from onegov.activity.models import OccasionNeed
from typing import TypeAlias
[docs]
VolunteerState: TypeAlias = Literal[
'open',
'contacted',
'confirmed',
]
[docs]
class Volunteer(Base, ContentMixin, TimestampMixin):
""" Describes a volunteer that has signed up to fulfill an
occasion need.
"""
[docs]
__tablename__ = 'volunteers'
#: The id of the record, may be used publicly
[docs]
id: Mapped[UUID] = mapped_column(
primary_key=True,
default=uuid4
)
#: The state of the volunteer
[docs]
state: Mapped[VolunteerState] = mapped_column(
Enum(
'open',
'contacted',
'confirmed',
name='volunteer_state'
),
default='open'
)
#: The need the volunteer signed up for
[docs]
need_id: Mapped[UUID] = mapped_column(ForeignKey('occasion_needs.id'))
[docs]
need: Mapped[OccasionNeed] = relationship(back_populates='volunteers')
#: A token linking multiple volunteer records (volunteers sign up for
#: multiple needs at once, and are then multiplexed here)
[docs]
token: Mapped[UUID] = mapped_column(default=uuid4)
#: The first name of the volunteer
[docs]
first_name: Mapped[str]
#: The last name of the volunteer
#: The address of the volunteer
#: The zip code of the volunteer
#: The place of the volunteer
#: The organisation of the volunteer
[docs]
organisation: Mapped[str | None]
#: The birth_date of the volunteer
[docs]
birth_date: Mapped[date]
#: The e-mail address of the volunteer
#: The phone number of the volunteer