Skip to content

Commit

Permalink
Merge pull request #1004 from onaio/csv-import-use-django-storage
Browse files Browse the repository at this point in the history
switch to using django storage for csv import processing
  • Loading branch information
ukanga committed Apr 12, 2017
2 parents 61f41e2 + 62b04b4 commit d23d2f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,13 @@ def csv_import(self, request, *args, **kwargs):
resp.update(submit_csv(request.user.username,
self.object, csv_file))
else:
tmp_file_path = utils.generate_tmp_path(csv_file)
csv_file.seek(0)
upload_to = os.path.join(request.user.username,
'csv_imports', csv_file.name)
file_name = default_storage.save(upload_to, csv_file)
task = submit_csv_async.delay(request.user.username,
self.object,
tmp_file_path)
file_name)
if task is None:
raise ParseError('Task not found')
else:
Expand Down
6 changes: 3 additions & 3 deletions onadata/libs/utils/csv_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import codecs
import cStringIO
import json
import uuid
Expand All @@ -11,6 +10,7 @@
from celery.backends.amqp import BacklogLimitExceeded
from celery.result import AsyncResult
from django.contrib.auth.models import User
from django.core.files.storage import default_storage

from onadata.apps.logger.models import Instance
from onadata.libs.utils.async_status import (FAILED, async_status,
Expand Down Expand Up @@ -110,8 +110,8 @@ def dict_pathkeys_to_nested_dicts(dictionary):


@task()
def submit_csv_async(username, xform, csv_file_temp_path):
with codecs.open(csv_file_temp_path, encoding='utf-8') as csv_file:
def submit_csv_async(username, xform, file_path):
with default_storage.open(file_path) as csv_file:
return submit_csv(username, xform, csv_file)


Expand Down

0 comments on commit d23d2f6

Please sign in to comment.