Commit 918416f0 by George Song Committed by GitHub

Merge pull request #15992 from open-craft/jill/openstack-course-import-export

Use django file storage URLs for all course export downloads.
parents 72c5d952 2f98f8af
...@@ -270,14 +270,14 @@ def import_status_handler(request, course_key_string, filename=None): ...@@ -270,14 +270,14 @@ def import_status_handler(request, course_key_string, filename=None):
return JsonResponse({"ImportStatus": status}) return JsonResponse({"ImportStatus": status})
def send_tarball(tarball): def send_tarball(tarball, size):
""" """
Renders a tarball to response, for use when sending a tar.gz file to the user. Renders a tarball to response, for use when sending a tar.gz file to the user.
""" """
wrapper = FileWrapper(tarball) wrapper = FileWrapper(tarball)
response = HttpResponse(wrapper, content_type='application/x-tgz') response = HttpResponse(wrapper, content_type='application/x-tgz')
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(tarball.name.encode('utf-8')) response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(tarball.name.encode('utf-8'))
response['Content-Length'] = os.path.getsize(tarball.name) response['Content-Length'] = size
return response return response
...@@ -381,6 +381,7 @@ def export_status_handler(request, course_key_string): ...@@ -381,6 +381,7 @@ def export_status_handler(request, course_key_string):
else: else:
# local file, serve from the authorization wrapper view # local file, serve from the authorization wrapper view
output_url = reverse_course_url('export_output_handler', course_key) output_url = reverse_course_url('export_output_handler', course_key)
elif task_status.state in (UserTaskStatus.FAILED, UserTaskStatus.CANCELED): elif task_status.state in (UserTaskStatus.FAILED, UserTaskStatus.CANCELED):
status = max(-(task_status.completed_steps + 1), -2) status = max(-(task_status.completed_steps + 1), -2)
errors = UserTaskArtifact.objects.filter(status=task_status, name='Error') errors = UserTaskArtifact.objects.filter(status=task_status, name='Error')
...@@ -423,7 +424,7 @@ def export_output_handler(request, course_key_string): ...@@ -423,7 +424,7 @@ def export_output_handler(request, course_key_string):
try: try:
artifact = UserTaskArtifact.objects.get(status=task_status, name='Output') artifact = UserTaskArtifact.objects.get(status=task_status, name='Output')
tarball = course_import_export_storage.open(artifact.file.name) tarball = course_import_export_storage.open(artifact.file.name)
return send_tarball(tarball) return send_tarball(tarball, artifact.file.storage.size(artifact.file.name))
except UserTaskArtifact.DoesNotExist: except UserTaskArtifact.DoesNotExist:
raise Http404 raise Http404
finally: finally:
......
...@@ -27,3 +27,6 @@ elif SWIFT_AUTH_URL and SWIFT_USERNAME and SWIFT_KEY: ...@@ -27,3 +27,6 @@ elif SWIFT_AUTH_URL and SWIFT_USERNAME and SWIFT_KEY:
DEFAULT_FILE_STORAGE = 'swift.storage.SwiftStorage' DEFAULT_FILE_STORAGE = 'swift.storage.SwiftStorage'
else: else:
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage' DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
# Use default file storage class set above for course import/export
COURSE_IMPORT_EXPORT_STORAGE = DEFAULT_FILE_STORAGE
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment