From 6ae408c2763dfe77f38c6e8af83029dfad7521d1 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 16:52:54 -0800 Subject: [PATCH 1/7] Remove workaround for older Pythons importlib.import_module is available since Python 2.7. --- import_export/formats/base_formats.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/import_export/formats/base_formats.py b/import_export/formats/base_formats.py index 7933760..68169a6 100644 --- a/import_export/formats/base_formats.py +++ b/import_export/formats/base_formats.py @@ -4,6 +4,7 @@ from django.utils.six import moves import sys import warnings import tablib +from importlib import import_module try: from tablib.compat import xlrd @@ -35,12 +36,6 @@ except ImportError: XLSX_IMPORT = False -try: - from importlib import import_module -except ImportError: - from django.utils.importlib import import_module - - class Format(object): def get_title(self): return type(self) From 5180a422a5aea0b0089495e8e1ead4f120b58a71 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 17:06:31 -0800 Subject: [PATCH 2/7] Remove workaround for older unsupported Djangos django.utils.encoding.force_text is available on all supported Djangos. Can remove workaround to simplify the imports. --- import_export/admin.py | 5 +---- import_export/resources.py | 5 +---- import_export/widgets.py | 7 +------ tests/core/tests/test_base_formats.py | 6 +----- tests/core/tests/test_resources.py | 6 +----- 5 files changed, 5 insertions(+), 24 deletions(-) diff --git a/import_export/admin.py b/import_export/admin.py index 3aad6d8..7f8409a 100644 --- a/import_export/admin.py +++ b/import_export/admin.py @@ -22,6 +22,7 @@ except ImportError: # Django<2.0 from django.conf import settings from django.template.defaultfilters import pluralize from django.utils.decorators import method_decorator +from django.utils.encoding import force_text from django.views.decorators.http import require_POST from .forms import ( @@ -38,10 +39,6 @@ from .results import RowResult from .tmp_storages import TempFolderStorage from .signals import post_export, post_import -try: - from django.utils.encoding import force_text -except ImportError: - from django.utils.encoding import force_unicode as force_text SKIP_ADMIN_LOG = getattr(settings, 'IMPORT_EXPORT_SKIP_ADMIN_LOG', False) TMP_STORAGE_CLASS = getattr(settings, 'IMPORT_EXPORT_TMP_STORAGE_CLASS', diff --git a/import_export/resources.py b/import_export/resources.py index 3723980..3d04b9c 100644 --- a/import_export/resources.py +++ b/import_export/resources.py @@ -19,6 +19,7 @@ from django.db.models.query import QuerySet from django.db.transaction import TransactionManagementError from django.utils import six from django.utils.safestring import mark_safe +from django.utils.encoding import force_text from . import widgets from .fields import Field @@ -34,10 +35,6 @@ except ImportError: from django.db.models.fields.related import ForeignObjectRel -try: - from django.utils.encoding import force_text -except ImportError: - from django.utils.encoding import force_unicode as force_text logger = logging.getLogger(__name__) # Set default logging handler to avoid "No handler found" warnings. diff --git a/import_export/widgets.py b/import_export/widgets.py index 1de4714..67b1fe1 100644 --- a/import_export/widgets.py +++ b/import_export/widgets.py @@ -4,18 +4,13 @@ from __future__ import unicode_literals from decimal import Decimal from datetime import datetime, date from django.utils import datetime_safe, timezone, six -from django.utils.encoding import smart_text +from django.utils.encoding import smart_text, force_text from django.utils.dateparse import parse_duration from django.conf import settings from django.core.exceptions import ObjectDoesNotExist import json import ast -try: - from django.utils.encoding import force_text -except ImportError: - from django.utils.encoding import force_unicode as force_text - class Widget(object): """ diff --git a/tests/core/tests/test_base_formats.py b/tests/core/tests/test_base_formats.py index 3a59377..583bce1 100644 --- a/tests/core/tests/test_base_formats.py +++ b/tests/core/tests/test_base_formats.py @@ -4,11 +4,7 @@ from __future__ import unicode_literals import os from django.test import TestCase - -try: - from django.utils.encoding import force_text -except ImportError: - from django.utils.encoding import force_unicode as force_text +from django.utils.encoding import force_text from import_export.formats import base_formats diff --git a/tests/core/tests/test_resources.py b/tests/core/tests/test_resources.py index c1e7b36..85838d9 100644 --- a/tests/core/tests/test_resources.py +++ b/tests/core/tests/test_resources.py @@ -14,6 +14,7 @@ from django.db.models import Count from django.db.models.fields import FieldDoesNotExist from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.utils.html import strip_tags +from django.utils.encoding import force_text from import_export import fields, resources, results, widgets from import_export.instance_loaders import ModelInstanceLoader @@ -29,11 +30,6 @@ try: except ImportError: from django.utils.datastructures import SortedDict as OrderedDict -try: - from django.utils.encoding import force_text -except ImportError: - from django.utils.encoding import force_unicode as force_text - class MyResource(resources.Resource): name = fields.Field() From b0d65cfdaf973c3b5636738b5be26477393abe96 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 17:15:57 -0800 Subject: [PATCH 3/7] Remove outdated workaround for OrderedDict collections.OrderedDict is available on all supported Pythons --- tests/core/tests/test_resources.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/core/tests/test_resources.py b/tests/core/tests/test_resources.py index c1e7b36..471c779 100644 --- a/tests/core/tests/test_resources.py +++ b/tests/core/tests/test_resources.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import tablib +from collections import OrderedDict from copy import deepcopy from datetime import date from decimal import Decimal @@ -24,11 +25,6 @@ from ..models import ( WithFloatField, Person, Role ) -try: - from collections import OrderedDict -except ImportError: - from django.utils.datastructures import SortedDict as OrderedDict - try: from django.utils.encoding import force_text except ImportError: From f84f3d486f9e40512350bc91ae5230795237ff4c Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 17:20:26 -0800 Subject: [PATCH 4/7] Trim trailing white space throughout the project Many editors clean up trailing white space on save. By removing it all in one go, it helps keep future diffs cleaner by avoiding spurious white space changes on unrelated lines. --- CODE_OF_CONDUCT.md | 1 - LICENSE | 6 +++--- docs/api_widgets.rst | 2 +- docs/changelog.rst | 4 ++-- import_export/mixins.py | 2 +- import_export/widgets.py | 4 ++-- tests/core/tests/test_admin_integration.py | 4 ++-- tests/database.db | Bin 70656 -> 70652 bytes 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d1ebd1d..9420974 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -71,4 +71,3 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage], versi available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org - diff --git a/LICENSE b/LICENSE index b49930c..c8b4a8a 100644 --- a/LICENSE +++ b/LICENSE @@ -4,10 +4,10 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright + + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. diff --git a/docs/api_widgets.rst b/docs/api_widgets.rst index f956ca3..94b69a5 100644 --- a/docs/api_widgets.rst +++ b/docs/api_widgets.rst @@ -28,7 +28,7 @@ Widgets .. autoclass:: import_export.widgets.DurationWidget :members: - + .. autoclass:: import_export.widgets.JSONWidget :members: diff --git a/docs/changelog.rst b/docs/changelog.rst index 7b7568f..012e83c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,7 +17,7 @@ Changelog - JSONWidget for jsonb fields (#803) -- Add ExportActionMixin (#809) +- Add ExportActionMixin (#809) - Add Import Export Permissioning #608 (#804) @@ -166,7 +166,7 @@ Changelog - Append rows to Result object via function call to allow overriding (#462) -- Add get_resource_kwargs to allow passing request to resource (#457) +- Add get_resource_kwargs to allow passing request to resource (#457) - Expose Django user to get_export_data() and export() (#447) diff --git a/import_export/mixins.py b/import_export/mixins.py index 5e44c19..abf3a32 100644 --- a/import_export/mixins.py +++ b/import_export/mixins.py @@ -64,7 +64,7 @@ class ExportViewMixin(object): class ExportViewFormMixin(ExportViewMixin, FormView): - def form_valid(self, form): + def form_valid(self, form): formats = self.get_export_formats() file_format = formats[ int(form.cleaned_data['file_format']) diff --git a/import_export/widgets.py b/import_export/widgets.py index 1de4714..99d1351 100644 --- a/import_export/widgets.py +++ b/import_export/widgets.py @@ -269,7 +269,7 @@ class SimpleArrayWidget(Widget): def render(self, value, obj=None): return self.separator.join(six.text_type(v) for v in value) - + class JSONWidget(Widget): """ Widget for a JSON object (especially required for jsonb fields in PostgreSQL database.) @@ -310,7 +310,7 @@ class ForeignKeyWidget(Widget): from import_export import fields, resources from import_export.widgets import ForeignKeyWidget - + class BookResource(resources.ModelResource): author = fields.Field( column_name='author', diff --git a/tests/core/tests/test_admin_integration.py b/tests/core/tests/test_admin_integration.py index 403e1b9..4b73640 100644 --- a/tests/core/tests/test_admin_integration.py +++ b/tests/core/tests/test_admin_integration.py @@ -64,7 +64,7 @@ class ImportExportAdminIntegrationTest(TestCase): response = self.client.post('/admin/core/book/process_import/', data, follow=True) self.assertEqual(response.status_code, 200) - self.assertContains(response, + self.assertContains(response, _('Import finished, with {} new and {} updated {}.').format( 1, 0, Book._meta.verbose_name_plural) ) @@ -101,7 +101,7 @@ class ImportExportAdminIntegrationTest(TestCase): response = self.client.post('/admin/core/book/process_import/', data, follow=True) self.assertEqual(response.status_code, 200) - self.assertContains(response, + self.assertContains(response, _('Import finished, with {} new and {} updated {}.').format( 1, 0, Book._meta.verbose_name_plural) ) diff --git a/tests/database.db b/tests/database.db index 73a74853370b43cf79b4dd79b64257a137d7fec2..a252d0b0830e9b1446514a5e95849e8862dc80d7 100644 GIT binary patch delta 22 ecmZoz!SZK0%Z7i>n_T`gZ}Rx3zxjVT;~W5n$qT9g delta 41 wcmeyfoTXs}%Z7i>Oq`sX|2h9>X5`$Yz{;|j$>*mw6DJo?=pXauU)4-A0A8UGr2qf` From c8daa20c7e1122fc0136a237020fbbde2fc48bdb Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 17:28:57 -0800 Subject: [PATCH 5/7] Clean up unused imports --- import_export/admin.py | 1 - import_export/resources.py | 1 - tests/core/tests/test_permissions.py | 8 -------- tests/core/tests/test_resources.py | 1 - tests/core/tests/test_widgets.py | 1 - tests/urls.py | 2 +- 6 files changed, 1 insertion(+), 13 deletions(-) diff --git a/import_export/admin.py b/import_export/admin.py index 3aad6d8..e6de616 100644 --- a/import_export/admin.py +++ b/import_export/admin.py @@ -20,7 +20,6 @@ try: except ImportError: # Django<2.0 from django.core.urlresolvers import reverse from django.conf import settings -from django.template.defaultfilters import pluralize from django.utils.decorators import method_decorator from django.views.decorators.http import require_POST diff --git a/import_export/resources.py b/import_export/resources.py index 3723980..3bebd34 100644 --- a/import_export/resources.py +++ b/import_export/resources.py @@ -9,7 +9,6 @@ from copy import deepcopy from diff_match_patch import diff_match_patch -from django import VERSION from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.management.color import no_style diff --git a/tests/core/tests/test_permissions.py b/tests/core/tests/test_permissions.py index f366c71..ce30bb5 100644 --- a/tests/core/tests/test_permissions.py +++ b/tests/core/tests/test_permissions.py @@ -2,18 +2,10 @@ from __future__ import unicode_literals import os.path -from django.contrib.auth import get_permission_codename from django.contrib.auth.models import Permission from django.test.utils import override_settings from django.test.testcases import TestCase from django.contrib.auth.models import User -from django.core.files.uploadedfile import SimpleUploadedFile -from django.utils.translation import ugettext_lazy as _ -from django.contrib.admin.models import LogEntry -from tablib import Dataset - -from core.admin import BookAdmin, AuthorAdmin, BookResource -from core.models import Category, Parent, Book class ImportExportPermissionTest(TestCase): diff --git a/tests/core/tests/test_resources.py b/tests/core/tests/test_resources.py index c1e7b36..d115f79 100644 --- a/tests/core/tests/test_resources.py +++ b/tests/core/tests/test_resources.py @@ -6,7 +6,6 @@ from datetime import date from decimal import Decimal from unittest import skip, skipUnless -from django import VERSION from django.conf import settings from django.contrib.auth.models import User from django.db import IntegrityError, DatabaseError diff --git a/tests/core/tests/test_widgets.py b/tests/core/tests/test_widgets.py index 7671692..39af41e 100644 --- a/tests/core/tests/test_widgets.py +++ b/tests/core/tests/test_widgets.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from decimal import Decimal from datetime import date, datetime, time, timedelta -from unittest import SkipTest from django.test.utils import override_settings from django.test import TestCase diff --git a/tests/urls.py b/tests/urls.py index 9a7f076..57c8709 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.conf.urls import url, include +from django.conf.urls import url from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib import admin From 9df6d8d66d180b6e2f96dbcae93280b254d2318d Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 23:57:43 -0800 Subject: [PATCH 6/7] Update URLs to use https:// (#863) --- README.rst | 4 ++-- import_export/formats/base_formats.py | 4 ++-- tests/core/tests/test_admin_integration.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index f0697dc..ec1f3da 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,7 @@ django-import-export :alt: Current version on PyPi .. image:: http://readthedocs.org/projects/django-import-export/badge/?version=stable - :target: http://django-import-export.readthedocs.io/en/stable/ + :target: https://django-import-export.readthedocs.io/en/stable/ :alt: Documentation django-import-export is a Django application and library for importing @@ -36,7 +36,7 @@ Features: .. image:: docs/_static/images/django-import-export-change.png -* Documentation: http://django-import-export.readthedocs.io/en/stable/ +* Documentation: https://django-import-export.readthedocs.io/en/stable/ * GitHub: https://github.com/django-import-export/django-import-export/ * Free software: BSD license * PyPI: https://pypi.org/project/django-import-export/ diff --git a/import_export/formats/base_formats.py b/import_export/formats/base_formats.py index 7933760..57b5cb2 100644 --- a/import_export/formats/base_formats.py +++ b/import_export/formats/base_formats.py @@ -77,7 +77,7 @@ class Format(object): def get_content_type(self): # For content types see - # http://www.iana.org/assignments/media-types/media-types.xhtml + # https://www.iana.org/assignments/media-types/media-types.xhtml return 'application/octet-stream' def can_import(self): @@ -156,7 +156,7 @@ class JSON(TextFormat): class YAML(TextFormat): TABLIB_MODULE = 'tablib.formats._yaml' - # See http://stackoverflow.com/questions/332129/yaml-mime-type + # See https://stackoverflow.com/questions/332129/yaml-mime-type CONTENT_TYPE = 'text/yaml' diff --git a/tests/core/tests/test_admin_integration.py b/tests/core/tests/test_admin_integration.py index 403e1b9..a9efe95 100644 --- a/tests/core/tests/test_admin_integration.py +++ b/tests/core/tests/test_admin_integration.py @@ -207,7 +207,7 @@ class ImportExportAdminIntegrationTest(TestCase): self.assertEqual(child.object_id, str(1)) def test_logentry_creation_with_import_obj_exception(self): - # from http://mail.python.org/pipermail/python-dev/2008-January/076194.html + # from https://mail.python.org/pipermail/python-dev/2008-January/076194.html def monkeypatch_method(cls): def decorator(func): setattr(cls, func.__name__, func) From b1278800cb04981fd51e4ff34bff082d32ffcf5a Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 4 Nov 2018 23:58:46 -0800 Subject: [PATCH 7/7] Use modern setuptools in setup.py (#862) As recommended by Python docs, use setuptools not distutils. See: https://docs.python.org/3/library/distutils.html > Most Python users will not want to use this module directly, but > instead use the cross-version tools maintained by the Python Packaging > Authority. In particular, setuptools is an enhanced alternative to > distutils ... setuptools is necessary for features like python_requires. --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 23864d3..fc85b82 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ -from distutils.core import setup -from setuptools import find_packages +from setuptools import find_packages, setup VERSION = __import__("import_export").__version__