Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/maps/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ def test_map_views(self) -> None:
response = self.client.get(url)
assert response.status_code == 200

def test_map_layer_json_view(self) -> None:
"""Test the map layers json view."""
url = reverse("maps:map_layers_json")
response = self.client.get(url)
assert response.status_code == 200

def test_marker_views(self) -> None:
"""Test the marker view."""
good = ["ffffff", "ffffff00"]
Expand Down
2 changes: 2 additions & 0 deletions src/maps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from django.urls import re_path

from .views import LayerGeoJSONView
from .views import LayerJsonView
from .views import MapMarkerView
from .views import MapProxyView

app_name = "maps"

urlpatterns = [
path("marker/<color>/", MapMarkerView.as_view(), name="marker"),
path("layers/", LayerJsonView.as_view(), name="map_layers_json"),
path(
"<slug:layer_slug>/",
include(
Expand Down
41 changes: 41 additions & 0 deletions src/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,47 @@ def render_to_response(self, context: dict, **kwargs) -> TemplateResponse:
)


class LayerJsonView(JsonView):
"""View for returning all available layers in json."""

def get_context_data(self, **kwargs) -> list:
"""Return the GeoJSON Data to the client."""
layers = []
for layer in Layer.objects.filter(public=True):
url = reverse(
"maps:map_layer_geojson",
kwargs={"layer_slug": layer.slug},
)
layers.append(
{
"name": layer.name,
"team": layer.responsible_team.name if layer.responsible_team else "None",
"camp": layer.responsible_team.camp.slug if layer.responsible_team else "all",
"url": self.request.build_absolute_uri(url),
"type": "layer",
},
)
for facility_type in FacilityType.objects.all():
url = reverse(
"facilities:facility_list_geojson",
kwargs={
"camp_slug": facility_type.responsible_team.camp.slug,
"facility_type_slug": facility_type.slug,
},
)
layers.append(
{
"name": facility_type.name,
"team": facility_type.responsible_team.name,
"camp": facility_type.responsible_team.camp.slug,
"url": self.request.build_absolute_uri(url),
"type": "facility",
},
)

return layers


class MapView(CampViewMixin, TemplateView):
"""Global map view."""

Expand Down
Loading