Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

MEI-15697 Staff tools - download failure #2168

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lms/djangoapps/instructor_task/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ def from_config(cls, config_name):
)
return DjangoStorageReportStore.from_config(config_name)

def _get_utf8_encoded_rows(self, rows):
def _get_utf8_encoded_rows(self, rows, encode_for_utf8=False):
"""
Given a list of `rows` containing unicode strings, return a
new list of rows with those strings encoded as utf-8 for CSV
compatibility.
"""
for row in rows:
if six.PY2:
if six.PY2 or encode_for_utf8:
yield [six.text_type(item).encode('utf-8') for item in row]
else:
yield [six.text_type(item) for item in row]
Expand Down Expand Up @@ -305,7 +305,7 @@ def store(self, course_id, filename, buff, batched=False):

self.storage.save(path, buff)

def store_rows(self, course_id, filename, rows):
def store_rows(self, course_id, filename, rows, encode_for_utf8=False, batched=False):
"""
Given a course_id, filename, and rows (each row is an iterable of
strings), write the rows to the storage backend in csv format.
Expand All @@ -315,9 +315,9 @@ def store_rows(self, course_id, filename, rows):
if six.PY2:
output_buffer.write(codecs.BOM_UTF8)
csvwriter = csv.writer(output_buffer)
csvwriter.writerows(self._get_utf8_encoded_rows(rows))
csvwriter.writerows(self._get_utf8_encoded_rows(rows, encode_for_utf8))
output_buffer.seek(0)
self.store(course_id, filename, output_buffer)
self.store(course_id, filename, output_buffer, batched)

def links_for(self, course_id):
"""
Expand Down