activity.models.period
======================

.. py:module:: activity.models.period


Classes
-------

.. autoapisummary::

   activity.models.period.PeriodMixin
   activity.models.period.PeriodMetaBase
   activity.models.period.PeriodMeta
   activity.models.period.Period


Module Contents
---------------

.. py:class:: PeriodMixin

   .. py:attribute:: timezone
      :type:  ClassVar[str]
      :value: 'Europe/Zurich'



   .. py:property:: active
      :type: sqlalchemy.Column[bool] | bool



   .. py:method:: as_local_datetime(day: datetime.date | datetime.datetime, end_of_day: bool = False) -> datetime.datetime

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



   .. py:property:: phase
      :type: str | None



   .. py:property:: wishlist_phase
      :type: bool



   .. py:property:: booking_phase
      :type: bool



   .. py:property:: payment_phase
      :type: bool



   .. py:property:: execution_phase
      :type: bool



   .. py:property:: archive_phase
      :type: bool



   .. py:property:: is_prebooking_in_future
      :type: bool



   .. py:property:: is_currently_prebooking
      :type: bool



   .. py:property:: is_prebooking_in_past
      :type: bool


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



   .. py:property:: is_booking_in_future
      :type: bool



   .. py:property:: is_currently_booking
      :type: bool



   .. py:property:: is_booking_in_past
      :type: bool



   .. py:property:: is_execution_in_past
      :type: bool



   .. py:property:: booking_limit
      :type: int | None


      Returns the max_bookings_per_attendee limit if it applies. 



.. py:class:: PeriodMetaBase

   Bases: :py:obj:`NamedTuple`


   .. py:attribute:: id
      :type:  uuid.UUID


   .. py:attribute:: title
      :type:  str


   .. py:attribute:: active
      :type:  bool


   .. py:attribute:: confirmed
      :type:  bool


   .. py:attribute:: confirmable
      :type:  bool


   .. py:attribute:: finalized
      :type:  bool


   .. py:attribute:: finalizable
      :type:  bool


   .. py:attribute:: archived
      :type:  bool


   .. py:attribute:: prebooking_start
      :type:  datetime.date


   .. py:attribute:: prebooking_end
      :type:  datetime.date


   .. py:attribute:: booking_start
      :type:  datetime.date


   .. py:attribute:: booking_end
      :type:  datetime.date


   .. py:attribute:: execution_start
      :type:  datetime.date


   .. py:attribute:: execution_end
      :type:  datetime.date


   .. py:attribute:: max_bookings_per_attendee
      :type:  int | None


   .. py:attribute:: booking_cost
      :type:  decimal.Decimal | None


   .. py:attribute:: all_inclusive
      :type:  bool


   .. py:attribute:: pay_organiser_directly
      :type:  bool


   .. py:attribute:: minutes_between
      :type:  int | None


   .. py:attribute:: alignment
      :type:  str | None


   .. py:attribute:: deadline_days
      :type:  int | None


   .. py:attribute:: book_finalized
      :type:  bool


   .. py:attribute:: cancellation_date
      :type:  datetime.date | None


   .. py:attribute:: cancellation_days
      :type:  int | None


   .. py:attribute:: age_barrier_type
      :type:  str


.. py:class:: PeriodMeta

   Bases: :py:obj:`PeriodMetaBase`, :py:obj:`PeriodMixin`


   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.


   .. py:method:: materialize(session: sqlalchemy.orm.Session) -> Period


   .. py:method:: __setattr__(name: str, value: object) -> NoReturn

      Implement setattr(self, name, value).



.. py:class:: Period

   Bases: :py:obj:`onegov.core.orm.Base`, :py:obj:`PeriodMixin`, :py:obj:`onegov.core.orm.mixins.TimestampMixin`


   Mixin providing created/modified timestamps for all records.

   The columns are deferred loaded as this is primarily for logging and future
   forensics.



   .. py:attribute:: __tablename__
      :value: 'periods'



   .. py:attribute:: id
      :type:  sqlalchemy.Column[uuid.UUID]


   .. py:attribute:: title
      :type:  sqlalchemy.Column[str]


   .. py:attribute:: active
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: confirmed
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: confirmable
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: finalized
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: finalizable
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: archived
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: prebooking_start
      :type:  sqlalchemy.Column[datetime.date]


   .. py:attribute:: prebooking_end
      :type:  sqlalchemy.Column[datetime.date]


   .. py:attribute:: booking_start
      :type:  sqlalchemy.Column[datetime.date]


   .. py:attribute:: booking_end
      :type:  sqlalchemy.Column[datetime.date]


   .. py:attribute:: execution_start
      :type:  sqlalchemy.Column[datetime.date]


   .. py:attribute:: execution_end
      :type:  sqlalchemy.Column[datetime.date]


   .. py:attribute:: data
      :type:  sqlalchemy.Column[dict[str, Any]]


   .. py:attribute:: max_bookings_per_attendee
      :type:  sqlalchemy.Column[int | None]


   .. py:attribute:: booking_cost
      :type:  sqlalchemy.Column[decimal.Decimal | None]


   .. py:attribute:: all_inclusive
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: pay_organiser_directly
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: minutes_between
      :type:  sqlalchemy.Column[int | None]


   .. py:attribute:: alignment
      :type:  sqlalchemy.Column[str | None]


   .. py:attribute:: deadline_days
      :type:  sqlalchemy.Column[int | None]


   .. py:attribute:: book_finalized
      :type:  sqlalchemy.Column[bool]


   .. py:attribute:: cancellation_date
      :type:  sqlalchemy.Column[datetime.date | None]


   .. py:attribute:: cancellation_days
      :type:  sqlalchemy.Column[int | None]


   .. py:attribute:: age_barrier_type
      :type:  sqlalchemy.Column[str]


   .. py:attribute:: __table_args__


   .. py:attribute:: occasions
      :type:  sqlalchemy.orm.relationship[list[onegov.activity.models.occasion.Occasion]]


   .. py:attribute:: bookings
      :type:  sqlalchemy.orm.relationship[list[onegov.activity.models.booking.Booking]]


   .. py:attribute:: invoices
      :type:  sqlalchemy.orm.relationship[list[onegov.activity.models.Invoice]]


   .. py:attribute:: publication_requests
      :type:  sqlalchemy.orm.relationship[list[onegov.activity.models.PublicationRequest]]


   .. py:method:: validate_age_barrier_type(key: str, age_barrier_type: str) -> str


   .. py:property:: age_barrier
      :type: onegov.activity.models.age_barrier.AgeBarrier



   .. py:method:: activate() -> None

      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.




   .. py:method:: deactivate() -> None

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




   .. py:method:: confirm() -> None

      Confirms the current period. 



   .. py:method:: archive() -> None

      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.




   .. py:method:: confirm_and_start_booking_phase() -> None

      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.




   .. py:property:: scoring
      :type: onegov.activity.matching.score.Scoring



   .. py:method:: materialize(session: sqlalchemy.orm.Session) -> Period