event.collections.events

Attributes

log

Classes

EventImportItem

Built-in immutable sequence.

EventCollection

Manage a list of events.

Module Contents

event.collections.events.log[source]
class event.collections.events.EventImportItem[source]

Bases: NamedTuple

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.

event: onegov.event.models.Event[source]
image: IO[bytes] | None[source]
image_filename: str | None[source]
pdf: IO[bytes] | None[source]
pdf_filename: str | None[source]
class event.collections.events.EventCollection(session: sqlalchemy.orm.Session, page: int = 0, state: onegov.event.models.event.EventState | None = None)[source]

Bases: onegov.core.collection.Pagination[onegov.event.models.Event]

Manage a list of events.

session[source]
state = None[source]
__eq__(other: object) → bool[source]
subset() → sqlalchemy.orm.Query[onegov.event.models.Event][source]
property page_index: int[source]
page_by_index(index: int) → Self[source]
for_state(state: onegov.event.models.event.EventState | None) → Self[source]

Returns a new instance of the collection with the given state.

query() → sqlalchemy.orm.Query[onegov.event.models.Event][source]
_get_unique_name(name: str) → str[source]

Create a unique, URL-friendly name.

add(title: str, start: datetime.datetime, end: datetime.datetime, timezone: str, autoclean: bool = True, **optional: Any) → onegov.event.models.Event[source]

Add a new event.

A unique, URL-friendly name is created automatically for this event using the title and optionally numbers for duplicate names.

Every time a new event is added, old, stale events are deleted unless disabled with the autoclean option.

Returns the created event or None if already automatically deleted.

delete(event: onegov.event.models.Event) → None[source]

Delete an event.

remove_stale_events(max_stale: datetime.datetime | None = None) → None[source]

Remove events which have never been submitted and are created more than five days ago.

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

Returns an event by its URL-friendly name.

by_id(id: uuid.UUID) → onegov.event.models.Event | None[source]

Return an event by its id. Hex representations work as well.

from_import(items: collections.abc.Iterable[EventImportItem | str], to_purge: list[str] | None = None, publish_immediately: bool = True, valid_state_transfers: collections.abc.Mapping[str, str] | None = None, published_only: bool = False, future_events_only: bool = False) → tuple[list[onegov.event.models.Event], list[onegov.event.models.Event], list[uuid.UUID]][source]

Add or updates the given events.

Only updates events which have changed. Uses Event.source_updated if available, falls back to comparing all relevant attributes.

Doesn’t change the states of events allowing to permanently withdraw imported events.

Doesn’t change the contents of events which have been modified locally (Event.locally_modified). State transfers and purging still apply to them.

Parameters:
  • items – A list of EventImportItem’s or event sources to keep from purging.

  • to_purge – Optionally removes all events with the given meta-source-prefix not present in the given events.

  • publish_immediately – Set newly added events to published, else let them be initiated.

  • valid_state_transfers –

    Dict of existing : remote state should be considered when updating.

    Example:

    {‘published’: ‘withdrawn’} would update locally published events if the remote has been withdrawn.

    for any {‘valid_state’: ‘withdrawn’} that lead to an update of the local state, an existing ticket will be close automatically.

    Be aware, that transferring state and creating tickets might lead to inconsistencies. So adjust the script in that case to handle the tickets automatically.

  • published_only – Do not import unpublished events. Still do not ignore state like withdrawn.

  • future_events_only – If set only events in the future will be imported

from_ical(ical: str, future_events_only: bool = False, event_image: IO[bytes] | None = None, event_image_name: str | None = None, default_categories: list[str] | None = None, default_filter_keywords: dict[str, list[str]] | None = None) → tuple[list[onegov.event.models.Event], list[onegov.event.models.Event], list[uuid.UUID]][source]

Imports the events from an iCalender string.

We assume the timezone to be Europe/Zurich! :param ical: ical to be imported :param future_events_only: if set only events in the future will be imported :param event_image: image file :param event_image_name: image name :param default_categories: categories applied if non is given in ical :param default_filter_keywords: default filter keywords, see event filter settings app.org.event_filter_type

from_minasa(xml_stream: bytes) → tuple[list[onegov.event.models.Event], list[onegov.event.models.Event], list[uuid.UUID]][source]
as_anthrazit_xml(request: onegov.core.request.CoreRequest, future_events_only: bool = True) → str[source]

Returns all published occurrences as xml for Winterthur. Anthrazit format according https://doc.anthrazit.org/ext/XML_Schnittstelle:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<import partner="???" partnerid"???" passwort"???" importid="??">
    <item status="1" suchbar="1"
          mutationsdatum="2023-08-18 08:23:30">
        <id>01</id>
        <titel>Titel der Seite</titel>
        <textmobile>2-3 Sätze des Text Feldes packed in
        CDATA</textmobile>
        <termin allday="1">
            <von>2011-08-06 00:00:00</von>
            <bis>2011-08-06 23:59:00</bis>
        </termin>
        <termin>
            ...
        </termin>
        <url_web>url</url_web>
        <url_bild>bild</url_bild>
        <hauptrubrik name="Naturmusuem">
            <rubrik>tag_1</rubrik>
            <rubrik>tag_2</rubrik>
        </hauptrubrik>
        <email></email>
        <telefon1></telefon1>
        <sf01>Veranstaltungspreis packed in CDATA</sf01>
        <veranstaltungsort>
            <title></title>
            <longitude></longitude>
            <latitude></latitude>
        </veranstaltungsort>
        ...
    </item>
    <item>
        ...
    </item>
</import>
Parameters:

future_events_only – if set, only future events will be returned, all events otherwise

Return type:

str

Returns:

xml string