From ad8697a12b066ec62868dbc669f1a86be620f470 Mon Sep 17 00:00:00 2001 From: Fernando Macedo Date: Tue, 13 Sep 2016 18:03:22 -0300 Subject: [PATCH 1/2] fix deprecated code of django 1.8 and 1.9 --- admin_export/templates/admin_export/export.html | 5 +++-- admin_export/views.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/admin_export/templates/admin_export/export.html b/admin_export/templates/admin_export/export.html index 8a3452b..031d35c 100644 --- a/admin_export/templates/admin_export/export.html +++ b/admin_export/templates/admin_export/export.html @@ -3,7 +3,8 @@ {% block extrahead %} {{ block.super }} - + + {% endblock %} diff --git a/admin_export/views.py b/admin_export/views.py index b6f1208..dbdceb4 100644 --- a/admin_export/views.py +++ b/admin_export/views.py @@ -2,7 +2,8 @@ from django.contrib import admin from django.contrib.contenttypes.models import ContentType from django.http.response import HttpResponse -from django.template import loader, Context +from django.template import Context, Engine +from django.utils.text import force_text from django.views.generic import TemplateView import csv from report_utils.mixins import GetFieldsMixin, DataExportMixin @@ -33,14 +34,14 @@ class ExtDataExportMixin(DataExportMixin): def list_to_html_response(self, data, title='', header=None): - html = loader.get_template_from_string(HTML_TEMPLATE).render(Context(locals())) + html = Engine().from_string(HTML_TEMPLATE).render(Context(locals())) return HttpResponse(html) def list_to_csv_response(self, data, title='', header=None): resp = HttpResponse(content_type="text/csv; charset=UTF-8") cw = csv.writer(resp) for row in chain([header] if header else [], data): - cw.writerow([unicode(s).encode(resp._charset) for s in row]) + cw.writerow([force_text(s).encode(resp.charset) for s in row]) return resp @@ -99,7 +100,7 @@ def post(self, request, **kwargs): return self.list_to_xlsx_response(data_list, header=fields) def get(self, request, *args, **kwargs): - if request.REQUEST.get("related"): # Dispatch to the other view + if request.GET.get("related", request.POST.get("related")): # Dispatch to the other view return AdminExportRelated.as_view()(request=self.request) return super(AdminExport, self).get(request, *args, **kwargs) From 0217660a5c294b9f328db92d40d5b9ac96e2ef1f Mon Sep 17 00:00:00 2001 From: Fernando Macedo Date: Wed, 14 Sep 2016 11:30:51 -0300 Subject: [PATCH 2/2] Adding tox to manage tests with multiple enviroments Tests are passing with Python2.7 and Django 1.8, 1.9 and 1.10 --- README.md | 9 ++++++++- setup.py | 2 +- tox.ini | 13 +++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tox.ini diff --git a/README.md b/README.md index 0ccf901..e4e5310 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Hello - this project is looking for a new maintainer. Please open an issue if you'd like to help maintain. +Hello - this project is looking for a new maintainer. Please open an issue if you'd like to help maintain. Most pressing issue is to support modern python/django See [#6](https://github.com/burke-software/django-admin-export/issues/6) @@ -35,6 +35,13 @@ Running tests 2. ``pip install -e . -r test_requirements.txt`` 3. ``py.test tests`` +Or to run tests with all supported environments: + +1. Acquire a checkout of the repository +2. Install tox with ``pip install tox`` +3. ``tox`` + + Security -------- diff --git a/setup.py b/setup.py index 99c11d5..a4bc17a 100755 --- a/setup.py +++ b/setup.py @@ -20,5 +20,5 @@ 'Intended Audience :: System Administrators', "License :: OSI Approved :: BSD License", ], - install_requires=['django-report-utils'], + install_requires=['django-report-utils', 'openpyxl'], ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..6800403 --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +[tox] +envlist = + {py27}-django1{8,9,10} + +[testenv] +setenv = + PYTHONPATH = {toxinidir}:{toxinidir}/admin_export +commands = py.test tests +deps = + django18: Django>=1.8,<1.9 + django19: Django>=1.9,<1.10 + django110: Django>=1.10,<1.11 + -r{toxinidir}/test_requirements.txt