From b154d90eed40958b1d3bc69e25c0dba77cfa8277 Mon Sep 17 00:00:00 2001 From: James Polley Date: Sun, 15 Oct 2017 14:59:57 +1000 Subject: [PATCH] Wrap input CSV in an TextIOWrapper Closes #24 --- vendor/symposion/schedule/forms.py | 7 ++++++- vendor/symposion/schedule/views.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/vendor/symposion/schedule/forms.py b/vendor/symposion/schedule/forms.py index fd549cd3..1ec67ea0 100644 --- a/vendor/symposion/schedule/forms.py +++ b/vendor/symposion/schedule/forms.py @@ -1,5 +1,6 @@ import csv import time +from io import TextIOWrapper from datetime import datetime @@ -66,6 +67,9 @@ class ScheduleSectionForm(forms.Form): def __init__(self, *args, **kwargs): self.schedule = kwargs.pop("schedule") + if 'encoding' in kwargs: + self.encoding = kwargs['encoding'] + kwargs.pop('encoding') super(ScheduleSectionForm, self).__init__(*args, **kwargs) def clean_filename(self): @@ -118,7 +122,8 @@ class ScheduleSectionForm(forms.Form): def build_schedule(self): created_items = [] - reader = csv.DictReader(self.cleaned_data.get('filename')) + f = TextIOWrapper(self.cleaned_data.get('filename'), encoding=self.encoding) + reader = csv.DictReader(f) data = [dict((k.strip(), v.strip()) for k, v in x.items()) for x in reader] # build rooms created_items.extend(self._build_rooms(data)) diff --git a/vendor/symposion/schedule/views.py b/vendor/symposion/schedule/views.py index 6983bdbb..c19271bd 100644 --- a/vendor/symposion/schedule/views.py +++ b/vendor/symposion/schedule/views.py @@ -129,7 +129,7 @@ def schedule_edit(request, slug=None): if request.method == "POST": form = ScheduleSectionForm( - request.POST, request.FILES, schedule=schedule + request.POST, request.FILES, schedule=schedule, encoding=request.encoding ) if form.is_valid(): if 'submit' in form.data: