From 3bea5b5d24a8a7b7c74613285537f5960049ea80 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Fri, 1 Nov 2019 17:54:01 +0500 Subject: [PATCH] BOM-1005 Fixing encoding issue. --- lms/djangoapps/instructor/tests/test_api.py | 1 + lms/djangoapps/instructor/views/api.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index 101e0fd226..81f575ae34 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -3293,6 +3293,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment self.assertTrue( body.endswith('"{user_id}","41","42"\n'.format(user_id=self.students[-1].id)) ) + self.assertIn("attachment; filename=org", response['Content-Disposition']) @patch('lms.djangoapps.instructor_task.models.logger.error') @patch.dict(settings.GRADES_DOWNLOAD, {'STORAGE_TYPE': 's3'}) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 86f705fc4a..1a8aed27ad 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -1943,7 +1943,9 @@ def get_anon_ids(request, course_id): # pylint: disable=unused-argument def csv_response(filename, header, rows): """Returns a CSV http response for the given header and rows (excel/utf-8).""" response = HttpResponse(content_type='text/csv') - response['Content-Disposition'] = u'attachment; filename={0}'.format(text_type(filename).encode('utf-8')) + response['Content-Disposition'] = u'attachment; filename={0}'.format( + text_type(filename).encode('utf-8') if six.PY2 else text_type(filename) + ) writer = csv.writer(response, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL) # In practice, there should not be non-ascii data in this query, # but trying to do the right thing anyway.