diff --git a/tests/test_nanterre_synchronize_federations.py b/tests/test_nanterre_synchronize_federations.py index dd859df..207e7b2 100644 --- a/tests/test_nanterre_synchronize_federations.py +++ b/tests/test_nanterre_synchronize_federations.py @@ -2,6 +2,7 @@ import csv +from django.utils import six from django.utils.encoding import force_bytes from django.utils.six import StringIO @@ -32,6 +33,12 @@ def test_synchronize_federations(settings, app, nanterre_classic_family, admin): response = response.click('Rapport') def check_csv_response(csv_response): + if six.PY3: + reader = csv.DictReader(StringIO(csv_response.text)) + reader.fieldnames = reader.reader.__next__() + else: + reader = csv.DictReader(StringIO(csv_response.content)) + reader.fieldnames = reader.reader.next() rows = list(reader) def rows_by_action(action): diff --git a/zoo/zoo_nanterre/forms.py b/zoo/zoo_nanterre/forms.py index 3a35814..4393ae1 100644 --- a/zoo/zoo_nanterre/forms.py +++ b/zoo/zoo_nanterre/forms.py @@ -15,6 +15,7 @@ # along with this program. If not, see . from django import forms +from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ from django.core.exceptions import ValidationError @@ -64,7 +65,7 @@ class SynchronizeFederationsForm(forms.Form): errors = [] for i, line in enumerate(csv_uploaded): try: - line.encode('ascii') + force_text(line).encode('ascii') # works with pyhton2 and 3 except (UnicodeEncodeError, UnicodeDecodeError) as e: errors.append(_(u'non-ASCII character on line {0} and column {1}').format( diff --git a/zoo/zoo_nanterre/synchronize_federations.py b/zoo/zoo_nanterre/synchronize_federations.py index 1dfa292..47169e8 100644 --- a/zoo/zoo_nanterre/synchronize_federations.py +++ b/zoo/zoo_nanterre/synchronize_federations.py @@ -23,6 +23,7 @@ from django.core.urlresolvers import reverse from django.conf import settings from django.db import DatabaseError from django.db.transaction import atomic +from django.utils import six from django.utils.encoding import force_bytes from django.utils.six import StringIO @@ -109,7 +110,10 @@ class SynchronizeFederationsImport(object): writer.writerow(['RSU ID', 'prenoms', 'nom de naissance', 'nom d\'usage', 'application', 'federation', 'action']) for action in self.actions: - action = [force_bytes(v) for v in action] + if six.PY3: + action = [v for v in action] + else: + action = [force_bytes(v) for v in action] writer.writerow(action) setattr(self.action, target + '_csv_filename', self.action.csv_filename + '-report.csv') diff --git a/zoo/zoo_nanterre/utils.py b/zoo/zoo_nanterre/utils.py index de1c7f6..66bd43c 100644 --- a/zoo/zoo_nanterre/utils.py +++ b/zoo/zoo_nanterre/utils.py @@ -17,7 +17,6 @@ # along with this program. If not, see . from __future__ import print_function -import six import functools import uuid import io @@ -45,6 +44,7 @@ from django.db import transaction from django.contrib.auth.hashers import make_password from django.http import HttpResponse +from django.utils import six from django.utils.timezone import now, make_aware from django.utils.encoding import force_bytes @@ -1268,7 +1268,7 @@ def individu_caption(individu): def csv_export_response(rows, filename): - if sys.version >= (3,): + if six.PY3: with io.StringIO(newline='') as f: writer = csv.writer(f) for row in rows: