From 22f9583dcc9d2c8986f92302aa772ae20b848fb2 Mon Sep 17 00:00:00 2001 From: Oliver Roick Date: Thu, 12 Jan 2017 15:58:09 +0100 Subject: [PATCH] Fix typo and code style --- cadasta/xforms/mixins/model_helper.py | 2 +- cadasta/xforms/tests/test_views_api.py | 2 +- cadasta/xforms/views/api.py | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cadasta/xforms/mixins/model_helper.py b/cadasta/xforms/mixins/model_helper.py index 72db3575d..c807410be 100644 --- a/cadasta/xforms/mixins/model_helper.py +++ b/cadasta/xforms/mixins/model_helper.py @@ -39,7 +39,7 @@ def _check_perm(self, user, project): roles = [superuser, org_admin, prj_manager, data_collector] assigned_policies = user.assigned_policies() if not any(role in assigned_policies for role in roles): - raise PermissionDenied(_("You don't have permission do contribute" + raise PermissionDenied(_("You don't have permission to contribute" " data to this project.")) def create_models(self, data, user): diff --git a/cadasta/xforms/tests/test_views_api.py b/cadasta/xforms/tests/test_views_api.py index fc4a147be..eec51dd0a 100644 --- a/cadasta/xforms/tests/test_views_api.py +++ b/cadasta/xforms/tests/test_views_api.py @@ -414,7 +414,7 @@ def test_unauthorized_user(self): response = self.request(method='POST', post_data=data, user=user, content_type='multipart/form-data') assert response.status_code == 403 - assert ("You don't have permission do contribute data to this project." + assert ("You don't have permission to contribute data to this project." in response.content) def test_questionnaire_not_found(self): diff --git a/cadasta/xforms/views/api.py b/cadasta/xforms/views/api.py index c48d8d7e5..b069e652d 100644 --- a/cadasta/xforms/views/api.py +++ b/cadasta/xforms/views/api.py @@ -53,9 +53,11 @@ def create(self, request, *args, **kwargs): instance = ModelHelper().upload_submission_data(request) except InvalidXMLSubmission as e: logger.debug(str(e)) - return self._sendErrorResponse(request, e, 'HTTP_400_BAD_REQUEST') + return self._sendErrorResponse(request, e, + status.HTTP_400_BAD_REQUEST) except PermissionDenied as e: - return self._sendErrorResponse(request, e, 'HTTP_403_FORBIDDEN') + return self._sendErrorResponse(request, e, + status.HTTP_403_FORBIDDEN) # If an already existing XFormSummission is sent back # don't create another. @@ -88,12 +90,12 @@ def create(self, request, *args, **kwargs): content_type='application/xml' ) - def _sendErrorResponse(self, request, e, code): + def _sendErrorResponse(self, request, e, status): message = _(OPEN_ROSA_ENVELOPE.format(message=str(e))) headers = self.get_openrosa_headers( request, location=False, content_length=False) return Response( - message, status=getattr(status, code), + message, status=status, headers=headers, content_type='application/xml' )