From 3c72913a7474d215522902f8ed8ce0c3740bca85 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 14 May 2020 10:55:59 +0200 Subject: [PATCH] Drop support for Django < 1.11 --- .travis.yml | 12 --------- CHANGES | 1 + example/mushrooms/settings.py | 14 +++++----- example/mushrooms/urls.py | 2 +- example/mushrooms/wsgi.py | 2 +- leaflet/__init__.py | 21 ++------------- leaflet/forms/widgets.py | 19 ++++--------- leaflet/templatetags/leaflet_tags.py | 6 +---- leaflet/tests/tests.py | 30 +++++++++------------ quicktest.py | 40 +++++++++++----------------- setup.py | 3 --- tox.ini | 9 ------- 12 files changed, 45 insertions(+), 114 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96bcc83c..901d396d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,18 +14,6 @@ matrix: include: - { python: "3.7", env: DJANGO=2.2 DATABASE=sqlite SPATIALITE_LIBRARY_PATH='mod_spatialite' } - - { python: "2.7", env: DJANGO=1.8 DATABASE=postgres } - - { python: "3.4", env: DJANGO=1.8 DATABASE=postgres } - - { python: "3.5", env: DJANGO=1.8 DATABASE=postgres } - - - { python: "2.7", env: DJANGO=1.9 DATABASE=postgres } - - { python: "3.4", env: DJANGO=1.9 DATABASE=postgres } - - { python: "3.5", env: DJANGO=1.9 DATABASE=postgres } - - - { python: "2.7", env: DJANGO=1.10 DATABASE=postgres } - - { python: "3.4", env: DJANGO=1.10 DATABASE=postgres } - - { python: "3.5", env: DJANGO=1.10 DATABASE=postgres } - - { python: "2.7", env: DJANGO=1.11 DATABASE=postgres } - { python: "3.4", env: DJANGO=1.11 DATABASE=postgres } - { python: "3.5", env: DJANGO=1.11 DATABASE=postgres } diff --git a/CHANGES b/CHANGES index 7469e701..643791dd 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ CHANGELOG 0.27.0 (unreleased) ------------------- +- Drop support for Django < 1.11 - Update Czech translations, add Slovak translations #269 - Add Arabic translation #274 diff --git a/example/mushrooms/settings.py b/example/mushrooms/settings.py index deca5ceb..cf71b7e0 100644 --- a/example/mushrooms/settings.py +++ b/example/mushrooms/settings.py @@ -4,10 +4,10 @@ Generated by 'django-admin startproject' using Django 1.10.2. For more information on this file, see -https://docs.djangoproject.com/en/1.10/topics/settings/ +https://docs.djangoproject.com/en/stable/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.10/ref/settings/ +https://docs.djangoproject.com/en/stable/ref/settings/ """ import os @@ -17,7 +17,7 @@ # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/stable/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = '_omc6hxq40u11no0uvi&g__lzj2n^4-dk#l#i+7+vgng!-bb^)' @@ -75,7 +75,7 @@ # Database -# https://docs.djangoproject.com/en/1.10/ref/settings/#databases +# https://docs.djangoproject.com/en/stable/ref/settings/#databases DATABASES = { 'default': { @@ -86,7 +86,7 @@ # Password validation -# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/stable/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -105,7 +105,7 @@ # Internationalization -# https://docs.djangoproject.com/en/1.10/topics/i18n/ +# https://docs.djangoproject.com/en/stable/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -119,7 +119,7 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.10/howto/static-files/ +# https://docs.djangoproject.com/en/stable/howto/static-files/ STATIC_URL = '/static/' MEDIA_URL = '/media/' diff --git a/example/mushrooms/urls.py b/example/mushrooms/urls.py index 49b28e42..6f94d51c 100644 --- a/example/mushrooms/urls.py +++ b/example/mushrooms/urls.py @@ -1,7 +1,7 @@ """mushrooms URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/1.10/topics/http/urls/ + https://docs.djangoproject.com/en/stable/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views diff --git a/example/mushrooms/wsgi.py b/example/mushrooms/wsgi.py index 0a8d9b26..b02f7083 100644 --- a/example/mushrooms/wsgi.py +++ b/example/mushrooms/wsgi.py @@ -4,7 +4,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/stable/howto/deployment/wsgi/ """ import os diff --git a/leaflet/__init__.py b/leaflet/__init__.py index e82777bd..1fa8627c 100644 --- a/leaflet/__init__.py +++ b/leaflet/__init__.py @@ -10,20 +10,11 @@ from urlparse import urlparse import warnings -try: - from collections import OrderedDict -except ImportError: - # python 2.6 compatibility (need to install ordereddict package). - from ordereddict import OrderedDict +from collections import OrderedDict from django.conf import settings from django.core.exceptions import ImproperlyConfigured - -try: - from django.templatetags.static import static -except ImportError: - from django.contrib.staticfiles.templatetags.staticfiles import static - +from django.templatetags.static import static from django.utils.translation import ugettext_lazy as _ try: @@ -31,8 +22,6 @@ except ImportError: from django.utils import six -import django - from .utils import memoized_lazy_function, ListWithLazyItems, ListWithLazyItemsRawIterator @@ -226,12 +215,6 @@ def _normalize_plugins_config(): default_app_config = 'leaflet.apps.LeafletConfig' -if django.VERSION >= (1, 8, 0): # otherwise is called in apps.py - if django.apps.apps.ready: - _normalize_plugins_config() -else: - _normalize_plugins_config() - class JSONLazyTranslationEncoder(DjangoJSONEncoder): def default(self, obj): diff --git a/leaflet/forms/widgets.py b/leaflet/forms/widgets.py index a83e53bf..e590fa63 100644 --- a/leaflet/forms/widgets.py +++ b/leaflet/forms/widgets.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from distutils.version import LooseVersion -from django import get_version from django import forms from django.contrib.gis.forms.widgets import BaseGeometryWidget from django.core import validators @@ -67,15 +65,8 @@ def _get_attrs(self, name, attrs=None): field_store_class=attrs.get('field_store_class', getattr(self, 'field_store_class', 'L.FieldStore'))) return attrs - # Django 1.11 changed how the widgets are rendered - if LooseVersion(get_version()) >= LooseVersion('1.11'): - def get_context(self, name, value, attrs): - value = None if value in validators.EMPTY_VALUES else value - context = super(LeafletWidget, self).get_context(name, value, attrs) - context.update(self._get_attrs(name, attrs)) - return context - else: - def render(self, name, value, attrs=None): - attrs = self._get_attrs(name, attrs) - value = None if value in validators.EMPTY_VALUES else value - return super(LeafletWidget, self).render(name, value, attrs) + def get_context(self, name, value, attrs): + value = None if value in validators.EMPTY_VALUES else value + context = super(LeafletWidget, self).get_context(name, value, attrs) + context.update(self._get_attrs(name, attrs)) + return context diff --git a/leaflet/templatetags/leaflet_tags.py b/leaflet/templatetags/leaflet_tags.py index d33797fc..e5290b70 100644 --- a/leaflet/templatetags/leaflet_tags.py +++ b/leaflet/templatetags/leaflet_tags.py @@ -45,14 +45,10 @@ def leaflet_js(plugins=None): plugin_names = _get_plugin_names(plugins) with_forms = PLUGIN_FORMS in plugin_names or PLUGIN_ALL in plugin_names FORCE_IMAGE_PATH = app_settings.get('FORCE_IMAGE_PATH') - template_options = hasattr(settings, 'TEMPLATES') \ - and len(settings.TEMPLATES) \ - and settings.TEMPLATES[0].get('OPTIONS', None) + template_options = settings.TEMPLATES[0].get('OPTIONS', None) if template_options and 'debug' in template_options: debug = template_options['debug'] - elif hasattr(settings, 'TEMPLATE_DEBUG'): - debug = settings.TEMPLATE_DEBUG else: debug = False diff --git a/leaflet/tests/tests.py b/leaflet/tests/tests.py index 65aaea49..90b9b0a5 100644 --- a/leaflet/tests/tests.py +++ b/leaflet/tests/tests.py @@ -3,17 +3,12 @@ import json import django -from django.contrib.staticfiles.storage import StaticFilesStorage, staticfiles_storage - -try: - from django.templatetags.static import static -except ImportError: - from django.contrib.staticfiles.templatetags.staticfiles import static - -from django.test import SimpleTestCase from django.contrib.admin import ModelAdmin, StackedInline from django.contrib.admin.options import BaseModelAdmin, InlineModelAdmin from django.contrib.gis.db import models as gismodels +from django.contrib.staticfiles.storage import StaticFilesStorage, staticfiles_storage +from django.templatetags.static import static +from django.test import SimpleTestCase from .. import PLUGINS, PLUGIN_FORMS, _normalize_plugins_config, JSONLazyTranslationEncoder @@ -330,16 +325,15 @@ class Meta: output = form.as_p() self.assertIn(".geom_type = 'Point'", output) - if django.VERSION >= (1, 6, 0): - def test_modelform_widget_conformity(self): - class DummyForm(django.forms.ModelForm): - class Meta: - model = DummyModel - fields = ['geom'] - widgets = {'geom': LeafletWidget()} - form = DummyForm() - output = form.as_p() - self.assertIn(".geom_type = 'Point'", output) + def test_modelform_widget_conformity(self): + class DummyForm(django.forms.ModelForm): + class Meta: + model = DummyModel + fields = ['geom'] + widgets = {'geom': LeafletWidget()} + form = DummyForm() + output = form.as_p() + self.assertIn(".geom_type = 'Point'", output) class LeafletGeoAdminMapTest(LeafletGeoAdminTest): diff --git a/quicktest.py b/quicktest.py index be51929c..a754e3c9 100644 --- a/quicktest.py +++ b/quicktest.py @@ -5,6 +5,7 @@ import sys import argparse from django.conf import settings +from django.test.runner import DiscoverRunner import django @@ -29,18 +30,6 @@ class QuickDjangoTest(object): 'django.contrib.messages', ] - if django.VERSION >= (1, 8, 0): - TEMPLATES = { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'OPTIONS': { - 'context_processors': [ - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ] - }, - 'APP_DIRS': True, - } - def __init__(self, *args, **kwargs): self.apps = kwargs.get('apps', []) self.database= kwargs.get('db', 'sqlite') @@ -48,7 +37,7 @@ def __init__(self, *args, **kwargs): def run_tests(self): """ - Fire up the Django test suite developed for version 1.2 + Fire up the Django test suite. """ if self.database == 'postgres': databases = { @@ -76,7 +65,17 @@ def run_tests(self): 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', - ] + ], + 'TEMPLATES': [{ + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'OPTIONS': { + 'context_processors': [ + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ] + }, + 'APP_DIRS': True, + }], } if 'SPATIALITE_LIBRARY_PATH' in os.environ: # If you get SpatiaLite-related errors, refer to this document @@ -87,19 +86,10 @@ def run_tests(self): # Example for macOS (with spatialite-tools installed using brew): # $ export SPATIALITE_LIBRARY_PATH='/usr/local/lib/mod_spatialite.dylib' conf['SPATIALITE_LIBRARY_PATH'] = os.getenv('SPATIALITE_LIBRARY_PATH') - if django.VERSION >= (1, 8, 0): - conf['TEMPLATES'] = self.TEMPLATES, settings.configure(**conf) - if django.VERSION >= (1, 7, 0): - # see: https://docs.djangoproject.com/en/dev/releases/1.7/#standalone-scripts - django.setup() - if django.VERSION >= (1, 6, 0): - # see: https://docs.djangoproject.com/en/dev/releases/1.6/#discovery-of-tests-in-any-test-module - from django.test.runner import DiscoverRunner as Runner - else: - from django.test.simple import DjangoTestSuiteRunner as Runner + django.setup() - failures = Runner().run_tests(self.apps, verbosity=1) + failures = DiscoverRunner().run_tests(self.apps, verbosity=1) if failures: # pragma: no cover sys.exit(failures) diff --git a/setup.py b/setup.py index d65e1f85..21ac8134 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,6 @@ import os from setuptools import setup, find_packages -import sys import codecs here = os.path.abspath(os.path.dirname(__file__)) @@ -10,8 +9,6 @@ 'Django', 'six', ] -if sys.version_info < (2, 7): - requires += ['ordereddict'] setup( name='django-leaflet', diff --git a/tox.ini b/tox.ini index 77a8330a..308b8012 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,5 @@ [tox] envlist = - {py27,py33,py34,py35}-django18, - {py27,py34,py35}-django19, - {py27,py34,py35}-django110, {py27,py34,py35,py36,py37}-django111, {py34,py35,py36,py37}-django20, {py35,py36,py37}-django21, @@ -13,9 +10,6 @@ envlist = [testenv] commands = coverage run ./quicktest.py leaflet --db={env:DATABASE:} deps = - django18: Django>=1.8,<1.9 - django19: Django>=1.9,<1.10 - django110: Django>=1.10,<1.11 django111: Django>=1.11,<2.0 django20: Django>=2.0,<2.1 django21: Django>=2.1,<2.2 @@ -29,9 +23,6 @@ passenv = DATABASE SPATIALITE_LIBRARY_PATH [travis:env] DJANGO = - 1.8: django18 - 1.9: django19 - 1.10: django110 1.11: django111 2.0: django20 2.1: django21