-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1773 from digitalfabrik/develop
Release `2022.10.1`
- Loading branch information
Showing
207 changed files
with
3,504 additions
and
872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
This module includes the POI category API endpoint. | ||
""" | ||
from django.http import JsonResponse | ||
|
||
from ...cms.models import POICategory | ||
from ..decorators import json_response | ||
|
||
|
||
def transform_location_category(location_category, language_slug): | ||
""" | ||
Function to create a JSON from a single location category object. | ||
:param location_category: The location category object which should be converted | ||
:type location_category: ~integreat_cms.cms.models.poi_categories.poi_category.POICategory | ||
:param language_slug: The slug of the requested language | ||
:type language_slug: str | ||
:return: Data necessary for API | ||
:rtype: dict | ||
""" | ||
if not location_category: | ||
return None | ||
category_translation = location_category.get_translation(language_slug) | ||
return { | ||
"id": location_category.id, | ||
"name": category_translation.name | ||
if category_translation | ||
else location_category.name, | ||
} | ||
|
||
|
||
@json_response | ||
# pylint: disable=unused-argument | ||
def location_categories(request, region_slug, language_slug): | ||
""" | ||
Function to return all POI categories as JSON. | ||
:param request: The current request | ||
:type request: ~django.http.HttpRequest | ||
:param region_slug: The slug of the requested region | ||
:type region_slug: str | ||
:param language_slug: The slug of the requested language | ||
:type language_slug: str | ||
:return: JSON object of all POI categories | ||
:rtype: ~django.http.JsonResponse | ||
""" | ||
region = request.region | ||
# Throw a 404 error when the language does not exist or is disabled | ||
region.get_language_or_404(language_slug, only_active=True) | ||
result = [ | ||
transform_location_category(location_category, language_slug) | ||
for location_category in POICategory.objects.all() | ||
] | ||
return JsonResponse( | ||
result, safe=False | ||
) # Turn off Safe-Mode to allow serializing arrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.