org.api
Attributes
Classes
Base class for protocol classes. |
|
Provides collections with pagination, if they implement a few |
|
Provides collections with pagination, if they implement a few |
|
An API endpoint. |
|
An API endpoint. |
|
An API endpoint. |
|
An API endpoint. |
|
An API endpoint. |
Functions
|
|
|
Returns the iso format of the modified or created field of item. |
|
Module Contents
- class org.api.CollectionLike[T: sqlalchemy.orm.DeclarativeBase][source]
Bases:
ProtocolBase 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: ...
- type org.api.FormOrExternalLink = FormDefinition | ExternalFormLink[source]
- type org.api.ResourceOrExternalLink = Resource | ExternalResourceLink[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.TicketCollectionfor an example.- __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() sqlalchemy.orm.Query[T][source]
Returns an SQLAlchemy query containing all records that should be considered for pagination.
- 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.TicketCollectionfor an example.- __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.
- abstractmethod subset() sqlalchemy.orm.Query[T][source]
Returns an SQLAlchemy query containing all records that should be considered for pagination.
- property subset_count: int[source]
Returns the total number of elements this pagination represents.
- 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.- 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 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 }
- item_links(item: onegov.event.models.Occurrence) dict[str, Any][source]
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.- 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.
- 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 }
- item_links(item: onegov.org.models.page.News) dict[str, Any][source]
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.- 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.
- 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 }
- item_links(item: onegov.org.models.page.Topic) dict[str, Any][source]
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]
- 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.- 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.
- 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 }
- item_links(item: onegov.org.models.directory.ExtendedDirectoryEntry) dict[str, Any][source]
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]
- class org.api.ResourceApiEndpoint[source]
Bases:
onegov.api.models.ApiEndpoint[ResourceOrExternalLink]
- 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.- _public_fields: tuple[str, Ellipsis] = ('academic_title', 'born', 'email', 'first_name', 'function', 'last_name', 'location_address',...[source]
- 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 }
- item_links(item: onegov.people.Person) dict[str, Any][source]
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) }