Skip to content

Commit

Permalink
import | extracted constants
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Oct 5, 2020
1 parent 96c08cd commit 04514ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/importers/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALREADY_QUEUED = 'The same import has been already queued'
INVALID_UPDATE_IF_EXISTS = "update_if_exists must be either 'true' or 'false'"

5 changes: 3 additions & 2 deletions core/importers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from core.common.swagger_parameters import update_if_exists_param, task_param, result_param, username_param
from core.common.utils import parse_bulk_import_task_id, task_exists, flower_get, queue_bulk_import
from core.importers.constants import ALREADY_QUEUED, INVALID_UPDATE_IF_EXISTS


class BulkImportView(APIView):
Expand All @@ -24,7 +25,7 @@ def post(self, request, import_queue=None):
update_if_exists = request.GET.get('update_if_exists', 'true')
if update_if_exists not in ['true', 'false']:
return Response(
dict(exception="update_if_exists must be either 'true' or 'false'"),
dict(exception=INVALID_UPDATE_IF_EXISTS),
status=status.HTTP_400_BAD_REQUEST
)
update_if_exists = update_if_exists == 'true'
Expand All @@ -33,7 +34,7 @@ def post(self, request, import_queue=None):
data = request.body.decode('utf-8') if isinstance(request.body, bytes) else request.body
task = queue_bulk_import(data, import_queue, username, update_if_exists)
except AlreadyQueued:
return Response(dict(exception='The same import has been already queued'), status=status.HTTP_409_CONFLICT)
return Response(dict(exception=ALREADY_QUEUED), status=status.HTTP_409_CONFLICT)

parsed_task = parse_bulk_import_task_id(task.id)

Expand Down

0 comments on commit 04514ae

Please sign in to comment.