Onegov Activity API

Models

class onegov.activity.models.activity.Activity(**kwargs)[source]

Describes an activity that is made available to participants on certain occasions (i.e. dates).

The activity describes the what’s going on, the occasion describes when and with whom.

id

An internal id for references (not public)

name

A nice id for the url, readable by humans

title

The title of the activity

order

The normalized title for sorting

lead = None

Describes the activity briefly

text = None

Describes the activity in detail

thumbnail = None

The thumbnail shown in the overview

username

The user to which this activity belongs to (organiser)

reporter

The user which initially reported this activity (same as username, but this value may not change after initialisation)

location

Describes the location of the activity

municipality

The municipality in which the activity is held, from the location

user

Access the user linked to this activity

occasions

The occasions linked to this activity

type

the type of the item, this can be used to create custom polymorphic subclasses of this class. See http://docs.sqlalchemy.org/en/improve_toc/ orm/extensions/declarative/inheritance.html.

state

the state of the activity

class onegov.activity.models.booking.Booking(**kwargs)[source]

Bookings are created by users for occasions.

Initially, bookings are open. In this state they represent a “wish” rather than booking.

Because bookings are wishes initially, they get a priority as well as a group code which links multiple bookings by multiple users together.

They system will try to figure out the best booking using the priority as well as the group code.

id

the public id of the booking

username

the user owning the booking

priority

the priority of the booking, a higher number = a higher priority

group_code

the group code of the booking, if missing the booking is not in a group

attendee_id

the attendee behind this booking

occasion_id

the occasion this booking belongs to

cost

the cost of the booking

score

the calculated score of the booking

state

the state of the booking

user

access the user linked to this booking

group_code_count(states=('open', 'accepted'))[source]

Returns the number of bookings with the same group code.

period_bound_booking_state(period)[source]

During pre-booking we don’t show the actual state of the booking, unless the occasion was cancelled, otherwise the user might see accepted bookings at a point where those states are not confirmed yet.

This methods interprets the period/state accordingly.

provisional_booking_cost(period=None)[source]

The costs of the final booking, including the booking costs of the period (if not all-inclusive).

This cost is written to the booking.cost when the period is confirmed.

set_priority_bit(index, bit)[source]

Changes the priority, setting the the nth bit from the right to the value of bit (index/n begins at 0).

The first bit (index=0) is reserved for starring/unstarring. The second bit (index=1) is reserved for nobble/unnobble.

As a result, starring is less influental than locking.

To give some context: Starring is used by the attendees to select which bookings they favor. Nobbling is used by administrators to force certain bookings to be preferred.

star(max_stars=3)[source]

Stars the current booking, up to a limit per period and attendee.

Starring sets the star-bit to 1.

Returns

True if successful (or already set), False if over limit.

class onegov.activity.models.occasion.Occasion(**kwargs)[source]

Describes a single occurrence of an Activity. “Occurence” would have been a good word for it too, but that’s used by onegov.event.

So occasion it is.

id

the public id of this occasion

meeting_point

Describes the meeting point of the occasion

age

The expected age of participants

spots

The expected number of participants

note

A note about the occurrence

cost

The cost of the occasion (max value is 100’000.00), the currency is assumed to be CHF as this system will probably never be used outside Switzerland

activity_id

The activity this occasion belongs to

period_id

The period this occasion belongs to

cancelled

True if the occasion has been cancelled

duration

The duration defined by the associated dates

order

The default order

exclude_from_overlap_check

Pretend like this occasion doesn’t use any time

exempt_from_booking_limit

This occasion can be booked, even if the booking limit has been reached (does not currently apply to the matching, only to confirmed periods)

active_days

Days on which this occasion is active

weekdays

Weekdays on which this occasion is active

bookings

The bookings linked to this occasion

dates

The dates associated with this occasion (loaded eagerly)

needs

The needs associated with this occasion

on_date_change()[source]

Date changes are not properly propagated to the observer for some reason, so we do this manually with a hook.

It’s a bit of a hack, but multiple dates per occasion had to be added at the last minute..

property anti_affinity_group

Uses the activity_id/period_id as an anti-affinity group to ensure that an attendee is never given two occasions of the same activity in a single period.

If that is wanted, the attendee is meant to do this after the matching has been done, with a direct booking.

property deadline

The date until which this occasion may be booked (inclusive).

property cancellation_deadline

The date until which bookings of this occasion may be cancelled by a mere member (inclusive).

If mere members are not allowed to do that, the deadline returns None.

Collections

class onegov.activity.collections.activity.ActivityCollection(session, type='*', page=0, filter=None)[source]
subset()[source]

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

property page_index

Returns the current page index (starting at 0).

page_by_index(index)[source]

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

query_base()[source]

Returns the query based used by 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.

for_filter(**keywords)[source]

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.

property used_tags

Returns a list of all the tags used on all activites of the current type.

property used_municipalities

Returns a list of all the municipalities on all activites of the current type

get_unique_name(name)[source]

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.

Utils

onegov.activity.utils.merge_ranges(ranges)[source]

Merges the given list of ranges into a list of ranges including only exclusive ranges. The ranges are turned into tuples to make them hashable.

onegov.activity.utils.generate_xml(payments)[source]

Creates an xml for import through ISO20022. Used for testing only.

onegov.activity.utils.dates_overlap(a, b, minutes_between=0, cut_end=True, alignment=None)[source]

Returns true if any time tuple in the list of tuples in a overlaps with a time tuple in b.