event.collections.events
Classes
Manage a list of events. |
Module Contents
- class event.collections.events.EventCollection(session: sqlalchemy.orm.Session, page: int = 0, state: EventState | None = None)[source]
Bases:
onegov.core.collection.Pagination
[onegov.event.models.Event
]Manage a list of events.
- __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[Event] [source]
Returns an SQLAlchemy query containing all records that should be considered for pagination.
- page_by_index(index: int) Self [source]
Returns the page at the given index. A page here means an instance of the class inheriting from the
Pagination
base class.
- for_state(state: EventState | None) Self [source]
Returns a new instance of the collection with the given state.
- 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.
- 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: Iterable[EventImportItem | str], purge: str | None = None, publish_immediately: bool = True, valid_state_transfers: 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.
- Parameters:
items – A list of
EventImportItem
’s or event sources to keep from purging.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 :type ical: str :param future_events_only: if set only events in the future will be imported :type future_events_only: bool :param event_image: image file :param event_image_name: image name :type event_image_name: str :param default_categories: categories applied if non is given in ical :type default_categories: [str] :param default_filter_keywords: default filter keywords, see event filter settings app.org.event_filter_type :type default_filter_keywords: dict(str, [str] | None)
- 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