event.collections.occurrences ============================= .. py:module:: event.collections.occurrences Attributes ---------- .. autoapisummary:: event.collections.occurrences.MISSING Classes ------- .. autoapisummary:: event.collections.occurrences.OccurenceSearchWidget event.collections.occurrences._Sentinel event.collections.occurrences.OccurrenceCollection event.collections.occurrences.tags Module Contents --------------- .. py:class:: OccurenceSearchWidget Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:property:: name :type: str .. py:property:: search_query :type: sqlalchemy.orm.Query[onegov.event.models.Occurrence] .. py:method:: adapt(query: sqlalchemy.orm.Query[onegov.event.models.Occurrence]) -> sqlalchemy.orm.Query[onegov.event.models.Occurrence] .. py:class:: _Sentinel(*args, **kwds) Bases: :py:obj:`enum.Enum` Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access:: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: MISSING .. py:data:: MISSING .. py:class:: OccurrenceCollection(session: sqlalchemy.orm.Session, page: int = 0, range: DateRange | None = None, start: datetime.date | None = None, end: datetime.date | None = None, outdated: bool = False, tags: Sequence[str] | None = None, filter_keywords: Mapping[str, list[str] | str] | None = None, locations: Sequence[str] | None = None, only_public: bool = False, search_widget: OccurenceSearchWidget | None = None, event_filter_configuration: dict[str, Any] | None = None, event_filter_fields: Sequence[ParsedField] | None = None) Bases: :py:obj:`onegov.core.collection.Pagination`\ [\ :py:obj:`onegov.event.models.Occurrence`\ ] Manages a list of occurrences. Occurrences are read only (no ``add`` method here), they are generated automatically when adding a new event. Occurrences can be filtered by relative date ranges (``today``, ``tomorrow``, ``weekend``, ``week``, ``month``, ``past``) or by a given start date and/or end date. The range filter is dominant and overwrites the start and end dates if provided. By default, only current occurrences are used. Occurrences can be additionally filtered by tags and locations. .. py:attribute:: date_ranges :type: tuple[DateRange, Ellipsis] :value: ('today', 'tomorrow', 'weekend', 'week', 'month', 'past') .. py:method:: __eq__(other: object) -> bool Returns True if the current and the other Pagination instance are equal. Used to find the current page in a list of pages. .. py:method:: subset() -> Query[Occurrence] Returns an SQLAlchemy query containing all records that should be considered for pagination. .. py:property:: search :type: str | None .. py:property:: search_query :type: Query[Occurrence] | None .. py:property:: page_index :type: int Returns the current page index (starting at 0). .. py:method:: page_by_index(index: int) -> typing_extensions.Self Returns the page at the given index. A page here means an instance of the class inheriting from the ``Pagination`` base class. .. py:method:: range_to_dates(range: DateRange | None, start: datetime.date | None = None, end: datetime.date | None = None) -> tuple[datetime.date | None, datetime.date | None] Returns the start and end date for the given range relative to now. Defaults to the given start and end date. Valid ranges are: - today - tomorrow - weekend (next or current Friday to Sunday) - week (current Monday to Sunday) - month (current) - past (events in the past) .. py:method:: for_keywords(singular: bool = False, **keywords: list[str]) -> typing_extensions.Self .. py:method:: for_toggled_keyword_value(keyword: str, value: str, singular: bool = False) -> typing_extensions.Self .. py:method:: for_filter(*, range: DateRange | None = None, start: date | None | MissingType = MISSING, end: date | None | MissingType = MISSING, outdated: bool | None = None, tags: Sequence[str] | None = None, tag: str | None = None, locations: Sequence[str] | None = None, location: str | None = None) -> typing_extensions.Self Returns a new instance of the collection with the given filters and copies the current filters if not specified. If a valid range is provided, start and end dates are ignored. If the range is invalid, it is ignored. Adds or removes a single tag/location if given. .. py:method:: without_keywords_and_tags() -> typing_extensions.Self .. py:method:: used_timezones() -> list[str] Returns a list of all the timezones used by the occurrences. .. py:method:: tag_counts() -> dict[str, int] Returns a dict with all existing tags as keys and the number of existence as value. .. py:method:: set_event_filter_configuration(config: dict[str, Any] | None) -> None .. py:method:: set_event_filter_fields(fields: Sequence[ParsedField] | None) -> None .. py:method:: valid_keywords(parameters: Mapping[str, T]) -> dict[str, T] .. py:method:: available_filters(sort_choices: bool = False, sortfunc: Callable[[str], SupportsRichComparison] | None = None) -> Iterable[tuple[str, str, list[str]]] Retrieve the filters with their choices. Return by default in the order of how they are defined in the config structure. To filter alphabetically, set sort_choices=True. :return tuple containing tuples with keyword, label and list of values :rtype tuple(tuples(keyword, title, values as list) .. py:method:: used_tags() -> set[str] Returns a list of all the tags used by all future occurrences. .. py:method:: query() -> Query[Occurrence] Queries occurrences with the set parameters. Finds occurrences which: * are between start and end date * have any of the tags * have any of the locations (exact word) Start and end date are assumed to be dates only and therefore without a timezone - we search for the given date in the timezone of the occurrence. In case of a search widget request the query will filter for events containing the text search term in e.g. title .. py:method:: by_name(name: str) -> onegov.event.models.Occurrence | None Returns an occurrence by its URL-friendly name. The URL-friendly name is automatically constructed as follows: ``unique name of the event``-``date of the occurrence`` e.g. ``squirrel-park-visit-6-2015-06-20`` .. py:method:: as_ical(request: onegov.core.request.CoreRequest) -> bytes Returns the the events of the given occurrences as iCalendar string. .. py:method:: as_xml(future_events_only: bool = True) -> bytes Returns all published occurrences as xml. The xml format was Winterthur's wish (no specs behind). Their mobile app will consume the events from xml Format: .. .. .. :param future_events_only: if set, only future events will be returned, all events otherwise :rtype: str :return: xml string .. py:class:: tags(tags: Sequence[str] = ()) Bases: :py:obj:`lxml.etree.ElementBase` Custom class as 'tag' is a member of class Element and cannot be used as tag name.