event.collections.occurrences

Module Contents

Classes

OccurenceSearchWidget

Base class for protocol classes.

_Sentinel

Generic enumeration.

OccurrenceCollection

Manages a list of occurrences.

tags

Custom class as 'tag' is a member of class Element and cannot be

Attributes

MISSING

class event.collections.occurrences.OccurenceSearchWidget[source]

Bases: 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:
        ...
property name: str[source]
property search_query: sqlalchemy.orm.Query[onegov.event.models.Occurrence][source]
adapt(query: sqlalchemy.orm.Query[onegov.event.models.Occurrence]) sqlalchemy.orm.Query[onegov.event.models.Occurrence][source]
class event.collections.occurrences._Sentinel[source]

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

MISSING[source]
event.collections.occurrences.MISSING[source]
class event.collections.occurrences.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)[source]

Bases: onegov.core.collection.Pagination[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.

property search: str | None[source]
property search_query: Query[Occurrence] | None[source]
property page_index: int[source]

Returns the current page index (starting at 0).

date_ranges: tuple[DateRange, Ellipsis] = ('today', 'tomorrow', 'weekend', 'week', 'month', 'past')[source]
__eq__(other: object) bool[source]

Returns True if the current and the other Pagination instance are equal. Used to find the current page in a list of pages.

subset() Query[Occurrence][source]

Returns an SQLAlchemy query containing all records that should be considered for pagination.

page_by_index(index: int) typing_extensions.Self[source]

Returns the page at the given index. A page here means an instance of the class inheriting from the Pagination base class.

range_to_dates(range: DateRange | None, start: datetime.date | None = None, end: datetime.date | None = None) tuple[datetime.date | None, datetime.date | None][source]

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)

for_keywords(singular: bool = False, **keywords: list[str]) typing_extensions.Self[source]
for_toggled_keyword_value(keyword: str, value: str, singular: bool = False) typing_extensions.Self[source]
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[source]

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.

without_keywords_and_tags() typing_extensions.Self[source]
used_timezones() list[str][source]

Returns a list of all the timezones used by the occurrences.

tag_counts() dict[str, int][source]

Returns a dict with all existing tags as keys and the number of existence as value.

set_event_filter_configuration(config: dict[str, Any] | None) None[source]
set_event_filter_fields(fields: Sequence[ParsedField] | None) None[source]
valid_keywords(parameters: Mapping[str, T]) dict[str, T][source]
available_filters(sort_choices: bool = False, sortfunc: Callable[[str], SupportsRichComparison] | None = None) Iterable[tuple[str, str, list[str]]][source]

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)

used_tags() set[str][source]

Returns a list of all the tags used by all future occurrences.

query() Query[Occurrence][source]

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

by_name(name: str) onegov.event.models.Occurrence | None[source]

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

as_ical(request: onegov.core.request.CoreRequest) str[source]

Returns the the events of the given occurrences as iCalendar string.

as_xml(future_events_only: bool = True) bytes[source]

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: <events>

<event>

<id></id> <title></title> <tags></tags>

<tag></tag>

<description></description> <start></start> <end></end> <location></location> <price></price> ..

</event> <event>

</event> ..

</events>

Parameters:

future_events_only – if set, only future events will be

returned, all events otherwise :rtype: str :return: xml string

class event.collections.occurrences.tags(tags: Sequence[str] = ())[source]

Bases: lxml.etree.ElementBase

Custom class as ‘tag’ is a member of class Element and cannot be used as tag name.