Add zone filter on backend
This commit is contained in:
parent
98a679eaf3
commit
de0b5abb7b
2 changed files with 10 additions and 1 deletions
|
@ -6,6 +6,7 @@ from django.db.models import Q
|
|||
from .models import EcologicalRegion, EcologicalDistrictLayer, SoilOrder, SoilVariant
|
||||
from .utils import get_point_from_coordinates
|
||||
|
||||
|
||||
def coordinate_filter(request, queryset):
|
||||
coordinates = request.query_params.get('coordinates')
|
||||
|
||||
|
@ -35,6 +36,12 @@ def soil_variant_filter(request, queryset):
|
|||
return queryset
|
||||
|
||||
|
||||
def zone_filter(request, queryset):
|
||||
zone = request.query_params.get('zone')
|
||||
zone_json = json.loads(zone)
|
||||
return queryset.filter(zones__id__contains=zone_json['id']).distinct()
|
||||
|
||||
|
||||
def soil_order_coordinate_filter(coordinates):
|
||||
pnt = get_point_from_coordinates(coordinates)
|
||||
try:
|
||||
|
@ -48,4 +55,5 @@ def ecological_district_coordinate_filter(coordinates):
|
|||
try:
|
||||
return EcologicalDistrictLayer.objects.filter(geom__intersects=pnt)
|
||||
except EcologicalDistrictLayer.DoesNotExist:
|
||||
raise Http404(f"Ecological district layer cannot be found for point {pnt}")
|
||||
raise Http404(
|
||||
f"Ecological district layer cannot be found for point {pnt}")
|
||||
|
|
|
@ -29,6 +29,7 @@ class PlantViewSet(viewsets.ModelViewSet):
|
|||
queryset = Plant.objects.all()
|
||||
queryset = coordinate_filter(self.request, queryset)
|
||||
queryset = soil_variant_filter(self.request, queryset)
|
||||
queryset = zone_filter(self.request, queryset)
|
||||
|
||||
return queryset
|
||||
|
||||
|
|
Loading…
Reference in a new issue