activity.collections.activity ============================= .. py:module:: activity.collections.activity Attributes ---------- .. autoapisummary:: activity.collections.activity.AvailabilityType activity.collections.activity.ActivityT activity.collections.activity.AVAILABILITY_VALUES Classes ------- .. autoapisummary:: activity.collections.activity.ActivityFilter activity.collections.activity.ActivityCollection Module Contents --------------- .. py:type:: AvailabilityType :canonical: Literal['none', 'few', 'many'] .. py:data:: ActivityT .. py:data:: AVAILABILITY_VALUES :type: set[AvailabilityType] .. py:class:: ActivityFilter(**keywords: typing_extensions.Unpack[FilterArgs]) .. py:attribute:: __slots__ :type: tuple[FilterKey, Ellipsis] :value: ('age_ranges', 'available', 'price_ranges', 'dateranges', 'durations', 'municipalities',... .. py:attribute:: singular .. py:attribute:: age_ranges :type: set[tuple[int, int]] .. py:attribute:: available :type: set[AvailabilityType] .. py:attribute:: price_ranges :type: set[tuple[int, int]] .. py:attribute:: dateranges :type: set[tuple[datetime.date, datetime.date]] .. py:attribute:: durations :type: set[int] .. py:attribute:: municipalities :type: set[str] .. py:attribute:: owners :type: set[str] .. py:attribute:: period_ids :type: set[uuid.UUID] .. py:attribute:: states :type: set[onegov.activity.models.activity.ActivityState] .. py:attribute:: tags :type: set[str] .. py:attribute:: timelines :type: set[str] .. py:attribute:: weekdays :type: set[int] .. py:attribute:: volunteers :type: set[bool] .. py:property:: keywords :type: dict[FilterKey, str | list[str]] .. py:method:: toggled(**keywords: typing_extensions.Unpack[ToggledArgs]) -> Self .. py:method:: adapt_available(values: set[str]) -> set[str] .. py:method:: adapt_num_ranges(values: set[str]) -> set[tuple[int, int]] .. py:method:: adapt_age_ranges(values: set[str]) -> set[tuple[int, int]] .. py:method:: adapt_price_ranges(values: set[str]) -> set[tuple[int, int]] .. py:method:: adapt_dateranges(values: set[str]) -> set[tuple[datetime.date, datetime.date]] .. py:method:: adapt_weekdays(values: set[str]) -> set[int] .. py:method:: adapt_period_ids(values: set[str]) -> set[uuid.UUID] .. py:method:: adapt_durations(values: set[str]) -> set[int] .. py:method:: adapt_volunteers(values: set[str]) -> set[bool] .. py:method:: encode(key: str, value: object) -> str | list[str] .. py:method:: contains_num_range(value: tuple[int, int], ranges: collections.abc.Iterable[tuple[int, int]]) -> bool .. py:method:: contains_age_range(age_range: tuple[int, int]) -> bool .. py:method:: contains_price_range(price_range: tuple[int, int]) -> bool .. py:class:: ActivityCollection(session: sqlalchemy.orm.Session, type: Literal['*', 'generic'] = '*', pages: tuple[int, int] | None = None, filter: ActivityFilter | None = None) ActivityCollection(session: sqlalchemy.orm.Session, type: str, pages: tuple[int, int] | None = None, filter: ActivityFilter | None = None) Bases: :py:obj:`onegov.core.collection.RangedPagination`\ [\ :py:obj:`ActivityT`\ ] Provides a pagination that supports loading multiple pages at once. This is useful in a context where a single button is used to 'load more' results one by one. In this case we need an URL that represents what's happening on the screen (multiple pages are shown at the same time). .. py:attribute:: session .. py:attribute:: type :value: '*' .. py:attribute:: pages :value: (0, 0) .. py:attribute:: filter .. py:method:: subset() -> sqlalchemy.orm.Query[ActivityT] Returns an SQLAlchemy query containing all records that should be considered for pagination. .. py:property:: page_range :type: tuple[int, int] Returns the current page range (starting at (0, 0)). .. py:method:: by_page_range(page_range: tuple[int, int] | None) -> Self Returns an instance of the collection limited to the given page range. .. py:property:: model_class :type: type[ActivityT] .. py:method:: query_base() -> sqlalchemy.orm.Query[ActivityT] Returns the query based used by :meth:`query`. Overriding this function is useful to apply a general filter to the query before any other filter is applied. For example, a policy can be enforced that only allows public activites. .. py:method:: query() -> sqlalchemy.orm.Query[ActivityT] .. py:method:: for_filter(**keywords: typing_extensions.Unpack[ToggledArgs]) -> Self Returns a new collection instance. The given tag is excluded if already in the list, included if not yet in the list. Same goes for the given state. Note that dateranges are excluded only if they match exactly. That is we don't care about overlaps at all. If the same exact daterange is found in the filter, it is excluded. .. py:method:: by_id(id: uuid.UUID) -> ActivityT | None .. py:method:: by_name(name: str) -> ActivityT | None .. py:method:: by_user(user: onegov.user.User) -> sqlalchemy.orm.Query[ActivityT] .. py:method:: by_username(username: str) -> sqlalchemy.orm.Query[ActivityT] .. py:property:: used_tags :type: set[str] Returns a list of all the tags used on *all* activites of the current type. .. py:property:: used_municipalities :type: set[str] Returns a list of all the municipalities on *all* activites of the current type .. py:method:: get_unique_name(name: str) -> str Given a desired name, finds a variant of that name that's not yet used. So if 'foobar' is already used, 'foobar-1' will be returned. .. py:method:: add(title: str, username: str, lead: str | None = None, text: markupsafe.Markup | None = None, tags: set[str] | None = None, name: str | None = None) -> ActivityT .. py:method:: delete(activity: onegov.activity.models.Activity) -> None .. py:method:: available_weeks(period: onegov.activity.models.Period | onegov.activity.models.PeriodMeta | None) -> collections.abc.Iterator[tuple[datetime.date, datetime.date]] .. py:method:: available_ages() -> tuple[int, int] | None