org.api

Attributes

FormOrExternalLink

ResourceOrExternalLink

Classes

CollectionLike

Base class for protocol classes.

PaginatedCollection

Provides collections with pagination, if they implement a few

PaginatedSumCollection

Provides collections with pagination, if they implement a few

EventApiEndpoint

An API endpoint.

NewsApiEndpoint

An API endpoint.

TopicApiEndpoint

An API endpoint.

DummyDirectorySearchWidget

DirectoryEntryApiEndpoint

An API endpoint.

FormApiEndpoint

ResourceApiEndpoint

PersonApiEndpoint

An API endpoint.

Functions

get_geo_location(→ dict[str, Any])

get_modified_iso_format(→ str)

Returns the iso format of the modified or created field of item.

apply_visibility_filters(→ sqlalchemy.orm.Query[T])

Module Contents

class org.api.CollectionLike[T: sqlalchemy.orm.DeclarativeBase][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[T](Protocol):
    def meth(self) -> T:
        ...
query() sqlalchemy.orm.Query[T][source]
by_id(id: Any, /) T | None[source]
org.api.get_geo_location(item: onegov.core.orm.mixins.ContentMixin) dict[str, Any][source]
org.api.get_modified_iso_format(item: onegov.core.orm.mixins.TimestampMixin) str[source]

Returns the iso format of the modified or created field of item.

Parameters:

item – db item e.g. agency, people, membership

Returns:

str iso representation of item last modification

org.api.apply_visibility_filters[T: sqlalchemy.orm.DeclarativeBase](request: onegov.org.request.OrgRequest, query: sqlalchemy.orm.Query[T], model_class: type[T]) sqlalchemy.orm.Query[T][source]
class org.api.PaginatedCollection[T: sqlalchemy.orm.DeclarativeBase](request: onegov.org.request.OrgRequest, collection: CollectionLike[T], model_class: type[T], batch_size: int, page: int = 0)[source]

Bases: onegov.core.collection.Pagination[T]

Provides collections with pagination, if they implement a few documented properties and methods.

See onegov.ticket.TicketCollection for an example.

request[source]
collection[source]
model_class[source]
page = 0[source]
batch_size[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.

by_id(id: onegov.core.collection.PKType) T | None[source]
subset() sqlalchemy.orm.Query[T][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.

property page_index: int[source]

Returns the current page index (starting at 0).

class org.api.PaginatedSumCollection[T: sqlalchemy.orm.DeclarativeBase](request: onegov.org.request.OrgRequest, collections: collections.abc.Sequence[tuple[CollectionLike[T], type[T]]], batch_size: int, page: int = 0)[source]

Bases: onegov.core.collection.Pagination[T]

Provides collections with pagination, if they implement a few documented properties and methods.

See onegov.ticket.TicketCollection for an example.

request[source]
collections[source]
batch_size[source]
page = 0[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.

by_id(id: onegov.core.collection.PKType) T | None[source]
abstractmethod subset() sqlalchemy.orm.Query[T][source]

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

property cached_subset: sqlalchemy.orm.Query[T][source]
Abstractmethod:

property counts: tuple[int, Ellipsis][source]
property subset_count: int[source]

Returns the total number of elements this pagination represents.

property batch: tuple[T, Ellipsis][source]

Returns the elements on the current page.

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.

property page_index: int[source]

Returns the current page index (starting at 0).

class org.api.EventApiEndpoint(request: onegov.core.request.CoreRequest, extra_parameters: dict[str, list[str]] | None = None, page: int | None = None)[source]

Bases: onegov.api.models.ApiEndpoint[onegov.event.models.Occurrence]

An API endpoint.

API endpoints wrap collection and do some filter mapping.

To add a new endpoint, inherit from this class and provide the missing functions and properties at the bottom. Note that the collection is expected to be to provide the functionality of onegov.core.collection.Pagination.

app: onegov.org.app.OrgApp[source]
endpoint = 'events'[source]
property filters: collections.abc.Mapping[str, collections.abc.Collection[str] | str | None][source]

A mapping of the available filter params to their corresponding description or a collection of possible values. If possible values are specified it is assumed that the filter can be specfied multiple times.

The description is optional and should only be used for non-trivial filters that don’t just accept arbitrary strings.

property title: str[source]

Return a human readable title for this endpoint

property description: str | None[source]

Return a human readable description for this endpoint

property _base_collection: onegov.event.collections.OccurrenceCollection[source]
get_date_filter(key: str, values: list[str]) datetime.date | None[source]
property collection: onegov.event.collections.OccurrenceCollection[source]

Return an instance of the collection with filters and page set.

item_data(item: onegov.event.models.Occurrence) dict[str, Any][source]

Return the data properties of the collection item as a dictionary.

For example:

{
    'name': 'Paul',
    'age': 40
}

Return the link properties of the collection item as a dictionary. Links can either be string or a linkable object.

For example:

{
    'website': 'https://onegov.ch',
    'friends': FriendsApiEndpoint(app).for_item(paul),
    'home': ApiEndpointCollection(app)
}
class org.api.NewsApiEndpoint(request: onegov.core.request.CoreRequest, extra_parameters: dict[str, list[str]] | None = None, page: int | None = None)[source]

Bases: onegov.api.models.ApiEndpoint[onegov.org.models.page.News]

An API endpoint.

API endpoints wrap collection and do some filter mapping.

To add a new endpoint, inherit from this class and provide the missing functions and properties at the bottom. Note that the collection is expected to be to provide the functionality of onegov.core.collection.Pagination.

app: onegov.org.app.OrgApp[source]
request: onegov.org.request.OrgRequest[source]
endpoint = 'news'[source]
property filters: collections.abc.Mapping[str, collections.abc.Collection[str] | str | None][source]

A mapping of the available filter params to their corresponding description or a collection of possible values. If possible values are specified it is assumed that the filter can be specfied multiple times.

The description is optional and should only be used for non-trivial filters that don’t just accept arbitrary strings.

property title: str[source]

Return a human readable title for this endpoint

property collection: Any[source]

Return an instance of the collection with filters and page set.

item_data(item: onegov.org.models.page.News) dict[str, Any][source]

Return the data properties of the collection item as a dictionary.

For example:

{
    'name': 'Paul',
    'age': 40
}

Return the link properties of the collection item as a dictionary. Links can either be string or a linkable object.

For example:

{
    'website': 'https://onegov.ch',
    'friends': FriendsApiEndpoint(app).for_item(paul),
    'home': ApiEndpointCollection(app)
}
class org.api.TopicApiEndpoint(request: onegov.core.request.CoreRequest, extra_parameters: dict[str, list[str]] | None = None, page: int | None = None)[source]

Bases: onegov.api.models.ApiEndpoint[onegov.org.models.page.Topic]

An API endpoint.

API endpoints wrap collection and do some filter mapping.

To add a new endpoint, inherit from this class and provide the missing functions and properties at the bottom. Note that the collection is expected to be to provide the functionality of onegov.core.collection.Pagination.

request: onegov.org.request.OrgRequest[source]
app: onegov.org.app.OrgApp[source]
endpoint = 'topics'[source]
property filters: collections.abc.Mapping[str, collections.abc.Collection[str] | str | None][source]

A mapping of the available filter params to their corresponding description or a collection of possible values. If possible values are specified it is assumed that the filter can be specfied multiple times.

The description is optional and should only be used for non-trivial filters that don’t just accept arbitrary strings.

property title: str[source]

Return a human readable title for this endpoint

property collection: Any[source]

Return an instance of the collection with filters and page set.

item_data(item: onegov.org.models.page.Topic) dict[str, Any][source]

Return the data properties of the collection item as a dictionary.

For example:

{
    'name': 'Paul',
    'age': 40
}

Return the link properties of the collection item as a dictionary. Links can either be string or a linkable object.

For example:

{
    'website': 'https://onegov.ch',
    'friends': FriendsApiEndpoint(app).for_item(paul),
    'home': ApiEndpointCollection(app)
}
class org.api.DummyDirectorySearchWidget(request: onegov.org.request.OrgRequest, term: str | None)[source]
name: str[source]
search_query: sqlalchemy.orm.Query[onegov.org.models.directory.ExtendedDirectoryEntry][source]
request[source]
term[source]
adapt[T](query: sqlalchemy.orm.Query[T]) sqlalchemy.orm.Query[T][source]
abstractmethod html(layout: Any) Any[source]
class org.api.DirectoryEntryApiEndpoint(request: onegov.org.request.OrgRequest, name: str, extra_parameters: dict[str, list[str]] | None = None, page: int | None = None)[source]

Bases: onegov.api.models.ApiEndpoint[onegov.org.models.directory.ExtendedDirectoryEntry]

An API endpoint.

API endpoints wrap collection and do some filter mapping.

To add a new endpoint, inherit from this class and provide the missing functions and properties at the bottom. Note that the collection is expected to be to provide the functionality of onegov.core.collection.Pagination.

request: onegov.org.request.OrgRequest[source]
app: onegov.org.app.OrgApp[source]
endpoint: str[source]
property filters: collections.abc.Mapping[str, collections.abc.Collection[str] | str | None][source]

A mapping of the available filter params to their corresponding description or a collection of possible values. If possible values are specified it is assumed that the filter can be specfied multiple times.

The description is optional and should only be used for non-trivial filters that don’t just accept arbitrary strings.

property title: str[source]

Return a human readable title for this endpoint

property description: str | None[source]

Return a human readable description for this endpoint

property directory: onegov.org.models.directory.ExtendedDirectory[source]
property collection: Any[source]

Return an instance of the collection with filters and page set.

for_page(page: int | None) DirectoryEntryApiEndpoint[source]

Return a new endpoint instance with the given page while keeping the current filters.

for_filter(**filters: Any) Self[source]

Return a new endpoint instance with the given filters while discarding the current filters and page.

by_id(id: onegov.core.collection.PKType) onegov.org.models.directory.ExtendedDirectoryEntry | None[source]

Return the item with the given ID from the collection.

item_data(item: onegov.org.models.directory.ExtendedDirectoryEntry) dict[str, Any][source]

Return the data properties of the collection item as a dictionary.

For example:

{
    'name': 'Paul',
    'age': 40
}

Return the link properties of the collection item as a dictionary. Links can either be string or a linkable object.

For example:

{
    'website': 'https://onegov.ch',
    'friends': FriendsApiEndpoint(app).for_item(paul),
    'home': ApiEndpointCollection(app)
}
class org.api.FormApiEndpoint[source]

Bases: onegov.api.models.ApiEndpoint[FormOrExternalLink]

app: onegov.org.app.OrgApp[source]
request: onegov.org.request.OrgRequest[source]
endpoint = 'forms'[source]
property title: str[source]
property collection: Any[source]
item_data(item: FormOrExternalLink) dict[str, Any][source]
class org.api.ResourceApiEndpoint[source]

Bases: onegov.api.models.ApiEndpoint[ResourceOrExternalLink]

app: onegov.org.app.OrgApp[source]
request: onegov.org.request.OrgRequest[source]
endpoint = 'resources'[source]
property title: str[source]
property collection: Any[source]
item_data(item: ResourceOrExternalLink) dict[str, Any][source]
class org.api.PersonApiEndpoint(request: onegov.core.request.CoreRequest, extra_parameters: dict[str, list[str]] | None = None, page: int | None = None)[source]

Bases: onegov.api.models.ApiEndpoint[onegov.people.Person]

An API endpoint.

API endpoints wrap collection and do some filter mapping.

To add a new endpoint, inherit from this class and provide the missing functions and properties at the bottom. Note that the collection is expected to be to provide the functionality of onegov.core.collection.Pagination.

app: onegov.org.app.OrgApp[source]
request: onegov.org.request.OrgRequest[source]
endpoint = 'people'[source]
_public_fields: tuple[str, Ellipsis] = ('academic_title', 'born', 'email', 'first_name', 'function', 'last_name', 'location_address',...[source]
property title: str[source]

Return a human readable title for this endpoint

property collection: Any[source]

Return an instance of the collection with filters and page set.

item_data(item: onegov.people.Person) dict[str, Any][source]

Return the data properties of the collection item as a dictionary.

For example:

{
    'name': 'Paul',
    'age': 40
}

Return the link properties of the collection item as a dictionary. Links can either be string or a linkable object.

For example:

{
    'website': 'https://onegov.ch',
    'friends': FriendsApiEndpoint(app).for_item(paul),
    'home': ApiEndpointCollection(app)
}