V3
Events
This module includes functions related to the event API endpoint.
- integreat_cms.api.v3.events.events(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
List all events of the region and transform result into JSON
- integreat_cms.api.v3.events.transform_available_languages(event_translation: EventTranslation, recurrence_date: date) dict[str, dict[str, str | None]] [source]
Function to create a JSON object of all available translations of an event translation. This is similar to event_translation.available_languages_dict embeds the recurrence date in the translation slug.
- integreat_cms.api.v3.events.transform_event(event: Event, custom_date: date | None = None) dict[str, Any] [source]
Function to create a JSON from a single event object.
- integreat_cms.api.v3.events.transform_event_recurrences(event_translation: EventTranslation, poi_translation: POITranslation | None, today: date) Iterator[dict[str, Any]] [source]
Yield all future recurrences of the event.
- Parameters:
event_translation (EventTranslation) – The event translation object which should be converted
poi_translation (POITranslation | None) – The poi translation object which is associated to this event
today (date) – The first date at which event may be yielded
- Returns:
An iterator over all future recurrences up to
settings.API_EVENTS_MAX_TIME_SPAN_DAYS
- Return type:
- integreat_cms.api.v3.events.transform_event_translation(event_translation: EventTranslation, poi_translation: POITranslation | None, recurrence_date: date | None = None) dict[str, Any] [source]
Function to create a JSON from a single event_translation object.
- Parameters:
event_translation (EventTranslation) – The event translation object which should be converted
poi_translation (POITranslation | None) – The poi translation object which is associated to this event
recurrence_date (date | None) – The recurrence date for the event
- Returns:
data necessary for API
- Return type:
Imprint
This module includes functions related to the imprint API endpoint.
- integreat_cms.api.v3.imprint.imprint(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Get imprint for language and return JSON object to client. If no imprint translation is available in the selected language, try to return the translation in the region default language.
- integreat_cms.api.v3.imprint.transform_imprint(imprint_translation: ImprintPageTranslation) dict[str, Any] [source]
Function to create a JSON from a single imprint_translation object.
- Parameters:
imprint_translation (ImprintPageTranslation) – single page translation object
- Returns:
data necessary for API
- Return type:
Languages
This module includes functions related to the languages API endpoint.
- integreat_cms.api.v3.languages.languages(request: HttpRequest, region_slug: str) JsonResponse [source]
Function to add all languages related to a region to a JSON.
- Parameters:
request (HttpRequest) – Django request
region_slug (str) – slug of a region
- Returns:
JSON object according to APIv3 languages endpoint definition
- Return type:
JsonResponse
Location Categories
This module includes the POI category API endpoint.
- integreat_cms.api.v3.location_categories.location_categories(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Function to return all POI categories as JSON.
- integreat_cms.api.v3.location_categories.transform_location_category(location_category: POICategory, language_slug: str) dict[str, Any] | None [source]
Function to create a JSON from a single location category object.
- Parameters:
location_category (POICategory) – The location category object which should be converted
language_slug (str) – The slug of the requested language
- Returns:
Data necessary for API
- Return type:
Locations
This module includes functions related to the locations/POIs API endpoint.
- integreat_cms.api.v3.locations.locations(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
List all POIs of the region and transform result into JSON
- integreat_cms.api.v3.locations.transform_poi(poi: POI | None) dict[str, Any] [source]
Function to create a JSON from a single poi object.
- integreat_cms.api.v3.locations.transform_poi_translation(poi_translation: POITranslation) dict[str, Any] [source]
Function to create a JSON from a single poi_translation object.
- Parameters:
poi_translation (POITranslation) – The poi translation object which should be converted
- Returns:
data necessary for API
- Return type:
Offers
This module includes functions related to the offers API endpoint.
- integreat_cms.api.v3.offers.get_post_data(offer: OfferTemplate, region: Region) dict[str, str] | None [source]
In case the url expects additional post data, it is stored inside the
post_data
-dict. Some offers depend on the location which is realized by adding the postal code of the current region to the request. If the offer template indicates that the postal code should be used asGET
-parameter, the class attributeuse_postal_code
has to be set topostal_code.POST
(seepostal_code
) and then the keysearch-plz
is automatically added to the post data. In case a third party service needs a different format, it has to be hard-coded here or we need other changes to the offer model.- Parameters:
offer (OfferTemplate) – one offer (formerly extra)
region (Region) – current region object
- Returns:
The post data of the offer’s url
- Return type:
- integreat_cms.api.v3.offers.get_url(offer: OfferTemplate, region: Region) str [source]
The offer should inherit the slug property from its template. This is the url to an API endpoint in most cases. Some offers depend on the location which is realized by adding the postal code of the current region to the request. If the offer template indicates that the postal code should be used as
GET
-parameter, the class attributeuse_postal_code
has to be set topostal_code.GET
(seepostal_code
) and the url has to end with the name of the required parameter-name, e.g.https://example.com/api?location=
.- Parameters:
offer (OfferTemplate) – one offer (formerly extra)
region (Region) – current region object
- Returns:
The url of an offer
- Return type:
- integreat_cms.api.v3.offers.offers(request: HttpRequest, region_slug: str, language_slug: str | None = None) JsonResponse [source]
Function to iterate through all offers related to a region and adds them to a JSON.
- integreat_cms.api.v3.offers.transform_offer(offer: OfferTemplate, region: Region) dict[str, Any] [source]
Function to create a JSON from a single offer Object.
- Parameters:
offer (OfferTemplate) – one offer (formerly extra)
region (Region) – current region object
- Returns:
data necessary for API
- Return type:
Pages
This module includes functions related to the pages API endpoint.
- integreat_cms.api.v3.pages.children(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Retrieves all children for a single page
- Parameters:
- Raises:
Http404 – HTTP status 404 if the request is malformed or no page with the given id or url exists.
- Returns:
JSON with the requested page descendants
- Return type:
JsonResponse
- integreat_cms.api.v3.pages.get_public_ancestor_translations(current_page: Page, language_slug: str) list[dict[str, Any]] [source]
Retrieves all ancestors (parent and all nodes up to the root node) of a page. If any ancestor is archived or has a missing translation, a 404 is raised.
- Parameters:
- Raises:
Http404 – HTTP status 404 if the request is malformed or no page with the given id or url exists.
- Returns:
JSON with the requested page ancestors
- Return type:
- integreat_cms.api.v3.pages.get_single_page(request: HttpRequest, language_slug: str) Page [source]
Helper function returning the desired page or a 404 if the requested page does not exist or is archived.
- Parameters:
request (HttpRequest) – The request that has been sent to the Django server
language_slug (str) – Code to identify the desired language
- Raises:
MultipleObjectsReturned – If the given url cannot be resolved unambiguously
Http404 – HTTP status 404 if the request is malformed or no page with the given id or url exists.
RuntimeError – If neither the id nor the url parameter is given
- Returns:
the requested page
- Return type:
- integreat_cms.api.v3.pages.pages(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Function to iterate through all non-archived pages of a region and return them as JSON.
- integreat_cms.api.v3.pages.parents(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Retrieves all ancestors (parent and all nodes up to the root node) of a page. If any ancestor is archived, an 404 is raised.
- Parameters:
- Raises:
Http404 – HTTP status 404 if the request is malformed or no page with the given id or url exists.
- Returns:
JSON with the requested page ancestors
- Return type:
JsonResponse
- integreat_cms.api.v3.pages.push_page_translation_content(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Retrieves all ancestors (parent and all nodes up to the root node) of a page
- Parameters:
- Raises:
Http404 – HTTP status 404 if the request is malformed or no page with the given id or url exists.
- Returns:
JSON with the requested page ancestors
- Return type:
JsonResponse
- integreat_cms.api.v3.pages.single_page(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
View function returning the desired page as a JSON or a 404 if the requested page does not exist.
- Parameters:
- Raises:
Http404 – HTTP status 404 if the request is malformed or no page with the given id or url exists.
- Returns:
JSON with the requested page and a HTTP status 200.
- Return type:
JsonResponse
- integreat_cms.api.v3.pages.transform_page(page_translation: PageTranslation) dict[str, Any] [source]
Function to create a dict from a single page_translation Object.
- Parameters:
page_translation (PageTranslation) – single page translation object
- Raises:
Http404 – HTTP status 404 if a parent is archived
- Returns:
data necessary for API
- Return type:
PDF Export
View to return PDF document containing the requested pages. Single pages may be requested by url parameter, if no parameter is included all pages related to the current region and language will be returned.
- integreat_cms.api.v3.pdf_export.pdf_export(request: HttpRequest, region_slug: str, language_slug: str) HttpResponseRedirect [source]
View function that either returns the requested page specified by the url parameter or returns all pages of current region and language as PDF document by forwarding the request to
generate_pdf()
- Parameters:
- Raises:
Http404 – HTTP status 404 if the requested page translation cannot be found.
- Returns:
The redirect to the generated PDF document
- Return type:
HttpResponseRedirect
Push Notifications
This module includes functions related to the push notification that are sent via firebase.
- integreat_cms.api.v3.push_notifications.sent_push_notifications(request: HttpRequest, region_slug: str, language_slug: str) JsonResponse [source]
Function to iterate through all sent push notifications related to a region and adds them to a JSON.
- integreat_cms.api.v3.push_notifications.transform_notification(pnt: PushNotificationTranslation) dict[str, Any] [source]
Function to create a JSON from a single push notification translation Object.
- Parameters:
pnt (PushNotificationTranslation) – A push notification translation
- Returns:
data necessary for API
- Return type:
Regions
This module includes functions related to the regions API endpoint.
- integreat_cms.api.v3.regions.region_by_slug(request: HttpRequest, region_slug: str) JsonResponse [source]
Retrieve a single region and transform result into JSON
- Returns:
JSON object according to APIv3 live regions endpoint definition
- Parameters:
request (HttpRequest)
region_slug (str)
- Return type:
JsonResponse
- integreat_cms.api.v3.regions.regions(_: HttpRequest) JsonResponse [source]
List all regions that are not archived and transform result into JSON
- Returns:
JSON object according to APIv3 regions endpoint definition
- Parameters:
_ (HttpRequest)
- Return type:
JsonResponse