Skip to content

Commit

Permalink
Create aggregation rest view for UI
Browse files Browse the repository at this point in the history
  • Loading branch information
vinikvuo committed Sep 15, 2023
1 parent 47b31d4 commit edde47c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mvj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
PlotSearchSubtypeViewSet,
PlotSearchTargetViewSet,
PlotSearchTypeViewSet,
PlotSearchUIDataView,
PlotSearchViewSet,
TargetStatusGeneratePDF,
)
Expand Down Expand Up @@ -259,6 +260,9 @@
name="target_status-pdf",
),
path("area_search_pdf/", AreaSearchGeneratePDF.as_view(), name="area-search-pdf"),
path(
"pub/plot_search_ui/", PlotSearchUIDataView.as_view(), name="pub_plot_search_ui"
),
path("auditlog/", AuditLogView.as_view(), name="auditlog"),
path("contact_exists/", ContactExistsView.as_view(), name="contact-exists"),
path(
Expand Down
18 changes: 17 additions & 1 deletion plotsearch/views/plot_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rest_framework import mixins, viewsets
from rest_framework.decorators import action
from rest_framework.filters import OrderingFilter
from rest_framework.permissions import IsAuthenticated
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework_gis.filters import InBBoxFilter
Expand Down Expand Up @@ -159,6 +159,22 @@ def get_answers_xlsx(self, *args, **kwargs):
return response


class PlotSearchUIDataView(APIView):
permission_classes = (AllowAny,)

def get(self, request):
aggregated_data = {
"plot_search": PlotSearch.objects.filter(
search_class="plot_search"
).count(),
"other_search": PlotSearch.objects.filter(
search_class="other_search"
).count(),
}

return Response(aggregated_data)


class PlotSearchTargetViewSet(mixins.UpdateModelMixin, viewsets.GenericViewSet):
queryset = PlotSearchTarget.objects.all()
serializer_class = PlotSearchTargetSerializer
Expand Down

0 comments on commit edde47c

Please sign in to comment.