Skip to content

Commit e74a82b

Browse files
authored
Added a view for showing all available layers for all camps/teams/fac… (#1888)
1 parent 8f23996 commit e74a82b

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/maps/tests/test_views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ def test_map_views(self) -> None:
176176
response = self.client.get(url)
177177
assert response.status_code == 200
178178

179+
def test_map_layer_json_view(self) -> None:
180+
"""Test the map layers json view."""
181+
url = reverse("maps:map_layers_json")
182+
response = self.client.get(url)
183+
assert response.status_code == 200
184+
179185
def test_marker_views(self) -> None:
180186
"""Test the marker view."""
181187
good = ["ffffff", "ffffff00"]

src/maps/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from django.urls import re_path
88

99
from .views import LayerGeoJSONView
10+
from .views import LayerJsonView
1011
from .views import MapMarkerView
1112
from .views import MapProxyView
1213

1314
app_name = "maps"
1415

1516
urlpatterns = [
1617
path("marker/<color>/", MapMarkerView.as_view(), name="marker"),
18+
path("layers/", LayerJsonView.as_view(), name="map_layers_json"),
1719
path(
1820
"<slug:layer_slug>/",
1921
include(

src/maps/views.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,47 @@ def render_to_response(self, context: dict, **kwargs) -> TemplateResponse:
123123
)
124124

125125

126+
class LayerJsonView(JsonView):
127+
"""View for returning all available layers in json."""
128+
129+
def get_context_data(self, **kwargs) -> list:
130+
"""Return the GeoJSON Data to the client."""
131+
layers = []
132+
for layer in Layer.objects.filter(public=True):
133+
url = reverse(
134+
"maps:map_layer_geojson",
135+
kwargs={"layer_slug": layer.slug},
136+
)
137+
layers.append(
138+
{
139+
"name": layer.name,
140+
"team": layer.responsible_team.name if layer.responsible_team else "None",
141+
"camp": layer.responsible_team.camp.slug if layer.responsible_team else "all",
142+
"url": self.request.build_absolute_uri(url),
143+
"type": "layer",
144+
},
145+
)
146+
for facility_type in FacilityType.objects.all():
147+
url = reverse(
148+
"facilities:facility_list_geojson",
149+
kwargs={
150+
"camp_slug": facility_type.responsible_team.camp.slug,
151+
"facility_type_slug": facility_type.slug,
152+
},
153+
)
154+
layers.append(
155+
{
156+
"name": facility_type.name,
157+
"team": facility_type.responsible_team.name,
158+
"camp": facility_type.responsible_team.camp.slug,
159+
"url": self.request.build_absolute_uri(url),
160+
"type": "facility",
161+
},
162+
)
163+
164+
return layers
165+
166+
126167
class MapView(CampViewMixin, TemplateView):
127168
"""Global map view."""
128169

0 commit comments

Comments
 (0)