activity.models.period

Classes

BookingPeriodMixin

_BookinPeriodMeta

BookingPeriodMeta

Built-in immutable sequence.

BookingPeriod

Base class used for declarative class definitions.

Module Contents

class activity.models.period.BookingPeriodMixin[source]
timezone: ClassVar[str] = 'Europe/Zurich'[source]
property active: sqlalchemy.orm.Mapped[bool] | bool[source]
as_local_datetime(day: datetime.date | datetime.datetime, end_of_day: bool = False) datetime.datetime[source]

Returns the moment of midnight in terms of the timezone it UTC

property phase: str | None[source]
property wishlist_phase: bool[source]
property booking_phase: bool[source]
property payment_phase: bool[source]
property execution_phase: bool[source]
property archive_phase: bool[source]
property is_prebooking_in_future: bool[source]
property is_currently_prebooking: bool[source]
property is_prebooking_in_past: bool[source]

Returns true if current date is after start of booking phase or if current date is after prebooking end.

property is_booking_in_future: bool[source]
property is_currently_booking: bool[source]
property is_booking_in_past: bool[source]
property is_execution_in_past: bool[source]
property booking_limit: int | None[source]

Returns the max_bookings_per_attendee limit if it applies.

class activity.models.period._BookinPeriodMeta[source]

Bases: NamedTuple

id: uuid.UUID[source]
title: str[source]
active: bool[source]
confirmed: bool[source]
confirmable: bool[source]
finalized: bool[source]
finalizable: bool[source]
archived: bool[source]
prebooking_start: datetime.date[source]
prebooking_end: datetime.date[source]
booking_start: datetime.date[source]
booking_end: datetime.date[source]
execution_start: datetime.date[source]
execution_end: datetime.date[source]
max_bookings_per_attendee: int | None[source]
booking_cost: decimal.Decimal | None[source]
all_inclusive: bool[source]
pay_organiser_directly: bool[source]
minutes_between: int | None[source]
alignment: str | None[source]
deadline_days: int | None[source]
book_finalized: bool[source]
cancellation_date: datetime.date | None[source]
cancellation_days: int | None[source]
age_barrier_type: str[source]
class activity.models.period.BookingPeriodMeta[source]

Bases: _BookinPeriodMeta, BookingPeriodMixin

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

materialize(session: sqlalchemy.orm.Session) BookingPeriod[source]
__setattr__(name: str, value: object) NoReturn[source]

Implement setattr(self, name, value).

class activity.models.period.BookingPeriod[source]

Bases: onegov.core.orm.Base, BookingPeriodMixin, onegov.core.orm.mixins.TimestampMixin

Base class used for declarative class definitions.

The _orm.DeclarativeBase allows for the creation of new declarative bases in such a way that is compatible with type checkers:

from sqlalchemy.orm import DeclarativeBase


class Base(DeclarativeBase):
    pass

The above Base class is now usable as the base for new declarative mappings. The superclass makes use of the __init_subclass__() method to set up new classes and metaclasses aren’t used.

When first used, the _orm.DeclarativeBase class instantiates a new _orm.registry to be used with the base, assuming one was not provided explicitly. The _orm.DeclarativeBase class supports class-level attributes which act as parameters for the construction of this registry; such as to indicate a specific _schema.MetaData collection as well as a specific value for :paramref:`_orm.registry.type_annotation_map`:

from typing_extensions import Annotated

from sqlalchemy import BigInteger
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy.orm import DeclarativeBase

bigint = Annotated[int, "bigint"]
my_metadata = MetaData()


class Base(DeclarativeBase):
    metadata = my_metadata
    type_annotation_map = {
        str: String().with_variant(String(255), "mysql", "mariadb"),
        bigint: BigInteger(),
    }

Class-level attributes which may be specified include:

Parameters:
  • metadata – optional _schema.MetaData collection. If a _orm.registry is constructed automatically, this _schema.MetaData collection will be used to construct it. Otherwise, the local _schema.MetaData collection will supersede that used by an existing _orm.registry passed using the :paramref:`_orm.DeclarativeBase.registry` parameter.

  • type_annotation_map – optional type annotation map that will be passed to the _orm.registry as :paramref:`_orm.registry.type_annotation_map`.

  • registry – supply a pre-existing _orm.registry directly.

Added in version 2.0: Added DeclarativeBase, so that declarative base classes may be constructed in such a way that is also recognized by PEP 484 type checkers. As a result, DeclarativeBase and other subclassing-oriented APIs should be seen as superseding previous “class returned by a function” APIs, namely _orm.declarative_base() and _orm.registry.generate_base(), where the base class returned cannot be recognized by type checkers without using plugins.

__init__ behavior

In a plain Python class, the base-most __init__() method in the class hierarchy is object.__init__(), which accepts no arguments. However, when the _orm.DeclarativeBase subclass is first declared, the class is given an __init__() method that links to the :paramref:`_orm.registry.constructor` constructor function, if no __init__() method is already present; this is the usual declarative constructor that will assign keyword arguments as attributes on the instance, assuming those attributes are established at the class level (i.e. are mapped, or are linked to a descriptor). This constructor is never accessed by a mapped class without being called explicitly via super(), as mapped classes are themselves given an __init__() method directly which calls :paramref:`_orm.registry.constructor`, so in the default case works independently of what the base-most __init__() method does.

Changed in version 2.0.1: _orm.DeclarativeBase has a default constructor that links to :paramref:`_orm.registry.constructor` by default, so that calls to super().__init__() can access this constructor. Previously, due to an implementation mistake, this default constructor was missing, and calling super().__init__() would invoke object.__init__().

The _orm.DeclarativeBase subclass may also declare an explicit __init__() method which will replace the use of the :paramref:`_orm.registry.constructor` function at this level:

class Base(DeclarativeBase):
    def __init__(self, id=None):
        self.id = id

Mapped classes still will not invoke this constructor implicitly; it remains only accessible by calling super().__init__():

class MyClass(Base):
    def __init__(self, id=None, name=None):
        self.name = name
        super().__init__(id=id)

Note that this is a different behavior from what functions like the legacy _orm.declarative_base() would do; the base created by those functions would always install :paramref:`_orm.registry.constructor` for __init__().

__tablename__ = 'periods'[source]
id: sqlalchemy.orm.Mapped[uuid.UUID][source]
title: sqlalchemy.orm.Mapped[str][source]
active: sqlalchemy.orm.Mapped[bool][source]
confirmed: sqlalchemy.orm.Mapped[bool][source]
confirmable: sqlalchemy.orm.Mapped[bool][source]
finalized: sqlalchemy.orm.Mapped[bool][source]
finalizable: sqlalchemy.orm.Mapped[bool][source]
archived: sqlalchemy.orm.Mapped[bool][source]
prebooking_start: sqlalchemy.orm.Mapped[datetime.date][source]
prebooking_end: sqlalchemy.orm.Mapped[datetime.date][source]
booking_start: sqlalchemy.orm.Mapped[datetime.date][source]
booking_end: sqlalchemy.orm.Mapped[datetime.date][source]
execution_start: sqlalchemy.orm.Mapped[datetime.date][source]
execution_end: sqlalchemy.orm.Mapped[datetime.date][source]
data: sqlalchemy.orm.Mapped[dict[str, Any]][source]
max_bookings_per_attendee: sqlalchemy.orm.Mapped[int | None][source]
booking_cost: sqlalchemy.orm.Mapped[decimal.Decimal | None][source]
all_inclusive: sqlalchemy.orm.Mapped[bool][source]
pay_organiser_directly: sqlalchemy.orm.Mapped[bool][source]
minutes_between: sqlalchemy.orm.Mapped[int | None][source]
alignment: sqlalchemy.orm.Mapped[str | None][source]
deadline_days: sqlalchemy.orm.Mapped[int | None][source]
book_finalized: sqlalchemy.orm.Mapped[bool][source]
cancellation_date: sqlalchemy.orm.Mapped[datetime.date | None][source]
cancellation_days: sqlalchemy.orm.Mapped[int | None][source]
age_barrier_type: sqlalchemy.orm.Mapped[str][source]
__table_args__[source]
occasions: sqlalchemy.orm.Mapped[list[onegov.activity.models.occasion.Occasion]][source]
bookings: sqlalchemy.orm.Mapped[list[onegov.activity.models.booking.Booking]][source]
invoices: sqlalchemy.orm.Mapped[list[onegov.activity.models.BookingPeriodInvoice]][source]
publication_requests: sqlalchemy.orm.Mapped[list[onegov.activity.models.PublicationRequest]][source]
validate_age_barrier_type(key: str, age_barrier_type: str) str[source]
property age_barrier: onegov.activity.models.age_barrier.AgeBarrier[source]
activate() None[source]

Activates the current period, causing all occasions and activites to update their status and book-keeping.

It also makes sure no other period is active.

deactivate() None[source]

Deactivates the current period, causing all occasions and activites to update their status and book-keeping.

confirm() None[source]

Confirms the current period.

archive() None[source]

Moves all accepted activities with an occasion in this period into the archived state, unless there’s already another occasion in a period newer than the current period.

confirm_and_start_booking_phase() None[source]

Confirms the period and sets the booking phase to now.

This is mainly an internal convenience function to activate the previous behaviour before a specific booking phase date was introduced.

property scoring: onegov.activity.matching.score.Scoring[source]
materialize(session: sqlalchemy.orm.Session) BookingPeriod[source]