api.models
Attributes
Exceptions
| Base class for all API exceptions. | |
| Base class for all API exceptions. | 
Classes
| A single instance of an item of a specific endpoint. | |
| An API endpoint. | |
| A collection of all available API endpoints. | |
| This is a Dummy, because morepath requires a model for linking. | |
Module Contents
- exception api.models.ApiException(message: str = 'Internal Server Error', status_code: int = 500, headers: dict[str, str] | None = None)[source]
- Bases: - Exception- Base class for all API exceptions. - Mainly used to ensure that all exceptions regarding the API are rendered with the correct content type. 
- exception api.models.ApiInvalidParamException(message: str = 'Invalid Parameter', status_code: int = 400)[source]
- Bases: - ApiException- Base class for all API exceptions. - Mainly used to ensure that all exceptions regarding the API are rendered with the correct content type. 
- class api.models.ApiEndpointItem(request: onegov.core.request.CoreRequest, endpoint: str, id: str)[source]
- Bases: - Generic[- onegov.core.collection._M]- A single instance of an item of a specific endpoint. - Passes all functionality to the specific API endpoint and is mainly used for routing. - property api_endpoint: ApiEndpoint[onegov.core.collection._M] | None[source]
 
- class api.models.ApiEndpoint(request: onegov.core.request.CoreRequest, extra_parameters: dict[str, str | None] | None = None, page: int | None = None)[source]
- Bases: - Generic[- onegov.core.collection._M]- 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.- for_page(page: int | None) Self | None[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. 
 - for_item(item: None) None[source]
- for_item(item: onegov.core.collection._M) ApiEndpointItem[onegov.core.collection._M]
- Return a new endpoint item instance with the given item. 
 - for_item_id(item_id: None) None[source]
- for_item_id(item_id: Any) ApiEndpointItem[Any]
- Return a new endpoint item instance with the given item id. 
 - get_filter(name: str, default: _DefaultT, empty: _EmptyT) str | _DefaultT | _EmptyT[source]
- get_filter(name: str, default: _DefaultT, empty: None = None) str | _DefaultT | None
- get_filter(name: str, default: None = None, *, empty: _EmptyT) str | _EmptyT | None
- get_filter(name: str, default: None = None, empty: None = None) str | None
- Returns the filter value with the given name. 
 - by_id(id: onegov.core.collection.PKType) onegov.core.collection._M | None[source]
- Return the item with the given ID from the collection. 
 - property batch: dict[ApiEndpointItem[onegov.core.collection._M], onegov.core.collection._M][source]
- Returns a dictionary with endpoint item instances and their titles. 
 - abstractmethod item_data(item: onegov.core.collection._M) dict[str, Any][source]
- Return the data properties of the collection item as a dictionary. - For example: - { 'name': 'Paul', 'age': 40 } 
 - abstractmethod item_links(item: onegov.core.collection._M) 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) } 
 - form(item: onegov.core.collection._M | None, request: onegov.core.request.CoreRequest) onegov.form.Form | None[source]
- Return a form for editing items of this collection. 
 - abstractmethod apply_changes(item: onegov.core.collection._M, form: Any) None[source]
- Apply the changes to the item based on the given form data. 
 
- class api.models.ApiEndpointCollection(request: onegov.core.request.CoreRequest)[source]
- A collection of all available API endpoints. - property endpoints: dict[str, ApiEndpoint[Any]][source]
 - get_endpoint(name: str, page: int = 0, extra_parameters: dict[str, Any] | None = None) ApiEndpoint[Any] | None[source]
 
- class api.models.AuthEndpoint(app: onegov.core.Framework)[source]
- This is a Dummy, because morepath requires a model for linking.