From 5562f8ea0e170a466db3cdc3b78dc85b5f22b726 Mon Sep 17 00:00:00 2001 From: pwilkins Date: Mon, 5 Oct 2015 16:16:17 -0400 Subject: [PATCH] Fix CCX grades csv file download In the CCX dashboard, the Student Admin tab has a `Download student grades` action. This action should download a CSV file containing grades, but currently displays the CSV content in the browser instead. This fix sets the `content-type` and `content-disposition` so that a CSV file download occurs. - fixes #93 --- AUTHORS | 3 ++- lms/djangoapps/ccx/tests/test_views.py | 6 ++++++ lms/djangoapps/ccx/views.py | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index f55a7959d2..7506665df5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -247,4 +247,5 @@ George Schneeloch Dustin Gadal Robert Raposa Giovanni Di Milia -Justin Abrahms \ No newline at end of file +Peter Wilkins +Justin Abrahms diff --git a/lms/djangoapps/ccx/tests/test_views.py b/lms/djangoapps/ccx/tests/test_views.py index a715c59eae..94a059b78b 100644 --- a/lms/djangoapps/ccx/tests/test_views.py +++ b/lms/djangoapps/ccx/tests/test_views.py @@ -733,6 +733,12 @@ class TestCCXGrades(SharedModuleStoreTestCase, LoginEnrollmentTestCase): ) response = self.client.get(url) self.assertEqual(response.status_code, 200) + # Are the grades downloaded as an attachment? + self.assertEqual( + response['content-disposition'], + 'attachment' + ) + headers, row = ( row.strip().split(',') for row in response.content.strip().split('\n') diff --git a/lms/djangoapps/ccx/views.py b/lms/djangoapps/ccx/views.py index f2a51259a0..e022875f81 100644 --- a/lms/djangoapps/ccx/views.py +++ b/lms/djangoapps/ccx/views.py @@ -615,4 +615,7 @@ def ccx_grades_csv(request, course, ccx=None): for row in rows: writer.writerow(row) - return HttpResponse(buf.getvalue(), content_type='text/plain') + response = HttpResponse(buf.getvalue(), content_type='text/csv') + response['Content-Disposition'] = 'attachment' + + return response