activity.collections.booking

Module Contents

Classes

BookingCollection

Abstract base class for generic types.

Attributes

ScoreFunction

activity.collections.booking.ScoreFunction: typing_extensions.TypeAlias[source]
class activity.collections.booking.BookingCollection(session: sqlalchemy.orm.Session, period_id: UUID | None = None, username: str | None = None)[source]

Bases: onegov.core.collection.GenericCollection[onegov.activity.models.Booking]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
property model_class: type[onegov.activity.models.Booking][source]
query() Query[Booking][source]
for_period(period: onegov.activity.models.Period) typing_extensions.Self[source]
for_username(username: str) typing_extensions.Self[source]
count(usernames: Collection[str] | Literal['*'] = '*', periods: Collection[UUID] | Literal['*'] = '*', states: Collection[str] | Literal['*'] = '*') int[source]

Returns the number of bookings, optionally filtered by usernames, periods and states.

All parameters may either be iterables or subqueries.

booking_count(username: str, states: Collection[str] | Literal['*'] = '*') int[source]

Returns the number of bookings in the active period.

by_user(user: onegov.user.User) Query[Booking][source]
by_username(username: str) Query[Booking][source]
by_occasion(occasion: onegov.activity.models.Occasion) Query[Booking][source]
add(user: onegov.user.User, attendee: onegov.activity.models.Attendee, occasion: onegov.activity.models.Occasion, priority: int | None = None, group_code: str | None = None) onegov.activity.models.Booking[source]
accept_booking(booking: onegov.activity.models.Booking) None[source]

Accepts the given booking, setting all other bookings which conflict with it to ‘blocked’.

Can only be done if the period has been confirmed already, the occasion is not yet full and the given booking doesn’t conflict with another accepted booking.

cancel_booking(booking: onegov.activity.models.Booking, score_function: ScoreFunction = booking_order, cascade: bool = False) None[source]

Cancels the given booking.

If cascade is set to False, this amounts to a simple state change and you can stop reading now.

If cascade is set to true, all denied bookings which have a chance of becoming accepted as a result (because the occasion frees up) are accepted according to their matching score (already accepted bookings are not touched).

All bookings which get unblocked for the current user are tried to be accepted as well, also with the highest score first. Contrary to the other influenced bookings, these bookings are not limited to the occasion of the cancelled booking.

This won’t necesserily create a new stable matching, but it will keep the operability as high as possible. It’s not ideal from a usability perspective as a single cancel may have a bigger impact than the user intended, but it beats having occasions fail with too few attendees when there are bookings waiting.

Can only be done if the period has been confirmed already and the booking is an accepted bookings. Open, cancelled, blocked and denied bookings can simply be deleted.