From 1cc258f404e81d3114897fdfee293f3ba8c04f20 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 1 Jul 2014 14:35:10 +0100 Subject: [PATCH] Don't install unicodecsv on Python 3 and fallback to pythons built in csv library it it isn't installed. --- setup.py | 44 +++++++++++++++++++++++------------ wagtail/wagtailforms/views.py | 14 +++++++++-- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/setup.py b/setup.py index 7b26817cd8..d4c750a19a 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,8 @@ #!/usr/bin/env python +import sys + + try: from setuptools import setup, find_packages except ImportError: @@ -16,6 +19,31 @@ except ImportError: pass +PY3 = sys.version_info[0] == 3 + + +install_requires = [ + "Django>=1.6.2,<1.7", + "South>=0.8.4", + "django-compressor>=1.3", + "django-libsass>=0.1", + "django-modelcluster>=0.1", + "django-taggit==0.11.2", + "django-treebeard==2.0", + "Pillow>=2.3.0", + "beautifulsoup4>=4.3.2", + "lxml>=3.3.0", + "Unidecode>=0.04.14", + "BeautifulSoup==3.2.1", # django-compressor gets confused if we have lxml but not BS3 installed +] + + +if not PY3: + install_requires += [ + "unicodecsv>=0.9.4" + ] + + setup( name='wagtail', version='0.3.1', @@ -40,20 +68,6 @@ setup( 'Framework :: Django', 'Topic :: Internet :: WWW/HTTP :: Site Management', ], - install_requires=[ - "Django>=1.6.2,<1.7", - "South>=0.8.4", - "django-compressor>=1.3", - "django-libsass>=0.1", - "django-modelcluster>=0.1", - "django-taggit==0.11.2", - "django-treebeard==2.0", - "Pillow>=2.3.0", - "beautifulsoup4>=4.3.2", - "lxml>=3.3.0", - 'unicodecsv>=0.9.4', - 'Unidecode>=0.04.14', - "BeautifulSoup==3.2.1", # django-compressor gets confused if we have lxml but not BS3 installed - ], + install_requires=install_requires, zip_safe=False, ) diff --git a/wagtail/wagtailforms/views.py b/wagtail/wagtailforms/views.py index 2174642c60..f0dce9010d 100644 --- a/wagtail/wagtailforms/views.py +++ b/wagtail/wagtailforms/views.py @@ -1,5 +1,11 @@ import datetime -import unicodecsv + +try: + import unicodecsv as csv + using_unicodecsv = True +except ImportError: + import csv + using_unicodecsv = False from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.exceptions import PermissionDenied @@ -65,7 +71,11 @@ def list_submissions(request, page_id): # return a CSV instead response = HttpResponse(content_type='text/csv; charset=utf-8') response['Content-Disposition'] = 'attachment;filename=export.csv' - writer = unicodecsv.writer(response, encoding='utf-8') + + if using_unicodecsv: + writer = csv.writer(response, encoding='utf-8') + else: + writer = csv.writer(response) header_row = ['Submission date'] + [label for name, label in data_fields]