Skip to content

Commit

Permalink
* Fix the export code so that it will work.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroff committed Jul 10, 2018
1 parent eed6c16 commit 1258b28
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django_kala/django_kala/platforms/aws/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def upload_document(self, content, key):
def upload_export(self, export_path):
key = 'exports/{0}'.format(uuid4())

s3 = boto3.client('s3')
s3 = boto3.resource('s3')
s3.meta.client.upload_file(
export_path,
settings.S3_STORAGE_BUCKET,
Expand Down
4 changes: 3 additions & 1 deletion django_kala/projects/tasks/export_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def run(self, *args, **kwargs):
# Save the path on the task for later cleanup
self.path = path

# TODO: If the file exists, we should append a unique id so that
# the files do not overwrite each other.
# Download all the documents into the documents dir.
for version in document.documentversion_set.all():
response = requests.get(manager.get_document_url(version), stream=True)
with open('{0}/{1}/{2}'.format(path, 'documents', version.file.name), 'wb') as f:
with open('{0}/{1}/{2}'.format(path, 'documents', version.name), 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
Expand Down
2 changes: 1 addition & 1 deletion django_kala/projects/tasks/export_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(self, *args, **kwargs):
for document in project.get_documents(user):
latest = document.get_latest()
response = requests.get(manager.get_document_url(latest), stream=True)
with open('{0}/{1}/{2}'.format(path, 'documents', latest.file.name), 'wb') as f:
with open('{0}/{1}/{2}'.format(path, 'documents', latest.name), 'wb') as f:
for chunk in response.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
Expand Down

0 comments on commit 1258b28

Please sign in to comment.