Skip to content

Commit

Permalink
make _handle_enketo_redirect a protected method and relocate it to th…
Browse files Browse the repository at this point in the history
…e correct place in the file
  • Loading branch information
RuthShryock committed Jul 31, 2024
1 parent 5fa367a commit 7aed3fe
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions kpi/views/v2/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7aed3fe

Please sign in to comment.