fix: Let csv.writer handle encoding for agenda_csv view (#5225)

This commit is contained in:
Jennifer Richards 2023-02-28 13:57:16 -04:00 committed by GitHub
parent 74990cfcb8
commit 1eb16c9002
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1805,18 +1805,18 @@ def agenda_extract_slide (item):
}
def agenda_csv(schedule, filtered_assignments):
response = HttpResponse(content_type="text/csv; charset=%s"%settings.DEFAULT_CHARSET)
encoding = 'utf-8'
response = HttpResponse(content_type=f"text/csv; charset={encoding}")
writer = csv.writer(response, delimiter=str(','), quoting=csv.QUOTE_ALL)
headings = ["Date", "Start", "End", "Session", "Room", "Area", "Acronym", "Type", "Description", "Session ID", "Agenda", "Slides"]
def write_row(row):
encoded_row = [v.encode('utf-8') if isinstance(v, str) else v for v in row]
while len(encoded_row) < len(headings):
encoded_row.append(None) # produce empty entries at the end as necessary
writer.writerow(encoded_row)
if len(row) < len(headings):
padding = [None] * (len(headings) - len(row)) # produce empty entries at the end as necessary
else:
padding = []
writer.writerow(row + padding)
def agenda_field(item):
agenda_doc = item.session.agenda()