diff --git a/kpi/views/v2/data.py b/kpi/views/v2/data.py index 7c86bc35ba..307d4d3438 100644 --- a/kpi/views/v2/data.py +++ b/kpi/views/v2/data.py @@ -437,16 +437,6 @@ def destroy(self, request, pk, *args, **kwargs): return Response(**json_response) - def handle_enketo_redirect(self, request, enketo_response, *args, **kwargs): - if request.path.strip('/').split('/')[-2] == 'redirect': - try: - enketo_url = enketo_response.data['url'] - except KeyError: - pass - else: - return HttpResponseRedirect(enketo_url) - return enketo_response - @action( detail=True, methods=['GET'], @@ -464,7 +454,7 @@ def enketo_edit(self, request, pk, *args, **kwargs): EnketoSessionAuthentication.prepare_response_with_csrf_cookie( request, enketo_response ) - return self.handle_enketo_redirect(request, enketo_response, *args, **kwargs) + return self._handle_enketo_redirect(request, enketo_response, *args, **kwargs) @action( detail=True, @@ -476,7 +466,7 @@ def enketo_edit(self, request, pk, *args, **kwargs): def enketo_view(self, request, pk, *args, **kwargs): submission_id = positive_int(pk) enketo_response = self._get_enketo_link(request, submission_id, 'view') - return self.handle_enketo_redirect(request, enketo_response, *args, **kwargs) + return self._handle_enketo_redirect(request, enketo_response, *args, **kwargs) def get_queryset(self): # This method is needed when pagination is activated and renderer is @@ -818,3 +808,13 @@ def _get_enketo_link( 'version_uid': version_uid, } ) + + def _handle_enketo_redirect(self, request, enketo_response, *args, **kwargs): + if request.path.strip('/').split('/')[-2] == 'redirect': + try: + enketo_url = enketo_response.data['url'] + except KeyError: + pass + else: + return HttpResponseRedirect(enketo_url) + return enketo_response