Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add indicator filters #172

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
14 changes: 14 additions & 0 deletions django_project/core/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ApiTag:

BASEMAPS = 'Basemaps'
DATA_BROWSER = 'Data Browser'
INDICATORS = 'indicators'


class ApiParams:
Expand Down Expand Up @@ -165,3 +166,16 @@ class ApiParams:
),
type=openapi.TYPE_STRING
)
SHORTCODE_CONTAINS = openapi.Parameter(
'shortcode__contains',
openapi.IN_QUERY,
description='Filter data by shortcode.',
type=openapi.TYPE_STRING
)

CREATED_BY_CONTAINS = openapi.Parameter(
'created__by__contains',
openapi.IN_QUERY,
description='Filter data by created date.',
type=openapi.TYPE_STRING
)
30 changes: 30 additions & 0 deletions django_project/geosight/data/api/v1/indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,51 @@
__date__ = '29/11/2023'
__copyright__ = ('Copyright 2023, Unicef')

from drf_yasg.utils import swagger_auto_schema
from rest_framework import viewsets

from geosight.data.models.indicator import Indicator
from geosight.data.serializer.indicator import (
IndicatorBasicListSerializer
)

from core.api_utils import ApiParams, common_api_params, ApiTag
from .base import BaseApiV1


class IndicatorViewSet(BaseApiV1, viewsets.ReadOnlyModelViewSet):
"""Indicator view set."""

model_class = Indicator
serializer_class = IndicatorBasicListSerializer
extra_exclude_fields = ['parameters']

@property
def queryset(self):
"""Return the queryset."""
return Indicator.permissions.list(self.request.user)

def get_queryset(self):
"""Return queryset of API."""
query = self.queryset
return self.filter_query(
self.request, query, ['page', 'page_size']
)

@swagger_auto_schema(
operation_id='indicators-get',
tags=[ApiTag.INDICATORS],
manual_parameters=[
*common_api_params,
ApiParams.NAME_CONTAINS,
ApiParams.DESCRIPTION_CONTAINS,
ApiParams.SHORTCODE_CONTAINS,
ApiParams.CREATED_BY_CONTAINS,
ApiParams.PROJECT_SLUGS,
ApiParams.PROJECT_IDS
],
operation_description='Return list of accessed indicators for the user.'
)
def list(self, request, *args, **kwargs):
"""List of indicators."""
return super().list(request, *args, **kwargs)