Repository: akvo/akvo-rsr

Issue:
Indicator overview endpoint



Discussion:

Resolving patch:
diff --git a/akvo/rest/urls.py b/akvo/rest/urls.py
--- a/akvo/rest/urls.py
+++ b/akvo/rest/urls.py
@@ -255,6 +255,9 @@
     url(r'v1/project/(?P<project_pk>[0-9]+)/result/(?P<result_pk>[0-9]+)/$',
         views.project_result_overview,
         name='project_result_overview'),
+    url(r'v1/project/(?P<project_pk>[0-9]+)/indicator/(?P<indicator_pk>[0-9]+)/$',
+        views.project_indicator_overview,
+        name='project_indicator_overview'),
 )
 
 # Program
diff --git a/akvo/rest/views/__init__.py b/akvo/rest/views/__init__.py
--- a/akvo/rest/views/__init__.py
+++ b/akvo/rest/views/__init__.py
@@ -114,7 +114,7 @@
                    request_organisation, current_user)
 from .user_management import invite_user
 from .user_projects import UserProjectsAccessViewSet
-from .project_overview import project_results, project_result_overview
+from .project_overview import project_results, project_result_overview, project_indicator_overview
 
 __all__ = [
     'AdministrativeLocationViewSet',
@@ -249,6 +249,7 @@
     'UserViewSet',
     'project_results',
     'project_result_overview',
+    'project_indicator_overview',
     'organisations_members',
     'project_roles',
     'project_invite_user',
diff --git a/akvo/rest/views/project_overview.py b/akvo/rest/views/project_overview.py
--- a/akvo/rest/views/project_overview.py
+++ b/akvo/rest/views/project_overview.py
@@ -7,7 +7,7 @@
 
 
 from akvo.rest.models import TastyTokenAuthentication
-from akvo.rsr.models import Project, Result, IndicatorPeriod, IndicatorPeriodData
+from akvo.rsr.models import Project, Result, Indicator, IndicatorPeriod, IndicatorPeriodData
 from akvo.rsr.models.result.utils import QUANTITATIVE, QUALITATIVE, PERCENTAGE_MEASURE, calculate_percentage
 from decimal import Decimal, InvalidOperation
 from django.http import Http404
@@ -79,6 +79,28 @@ def project_result_overview(request, project_pk, result_pk):
     return Response(data)
 
 
+@api_view(['GET'])
+@authentication_classes([SessionAuthentication, TastyTokenAuthentication])
+def project_indicator_overview(request, project_pk, indicator_pk):
+    queryset = Indicator.objects.prefetch_related('periods').select_related('result__project')
+    indicator = get_object_or_404(queryset, pk=indicator_pk)
+    project = indicator.result.project
+    if project.id != int(project_pk) or not request.user.has_perm('rsr.view_project', project):
+        raise Http404
+
+    data = {
+        'id': indicator.id,
+        'title': indicator.title,
+        'description': indicator.description,
+        'period_count': len(indicator.periods.all()),
+        'type': 'quantitative' if indicator.type == QUANTITATIVE else 'qualitative',
+        'measure': (
+            'unit' if indicator.measure == '1' else 'percentage' if indicator.measure == '2' else None),
+        'periods': _drilldown_indicator_periods_contributions(indicator)
+    }
+    return Response(data)
+
+
 def _drilldown_indicator_periods_contributions(indicator, aggregate_targets=False):
     periods = _get_indicator_periods_hierarchy_flatlist(indicator)
     periods_tree = _make_periods_hierarchy_tree(periods)


Test patch: