From 6390279a5eba1dc47fc12627204484fda67d3825 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 25 May 2016 20:24:54 +0200 Subject: [PATCH] Dropped Django 1.7 support --- .travis.yml | 3 - README.rst | 2 +- debug_toolbar/compat.py | 53 ----------- debug_toolbar/panels/templates/panel.py | 87 +++++++------------ debug_toolbar/panels/templates/views.py | 4 +- .../templates/debug_toolbar/panels/cache.html | 2 +- .../debug_toolbar/panels/headers.html | 2 +- .../debug_toolbar/panels/logging.html | 2 +- .../debug_toolbar/panels/request.html | 2 +- .../debug_toolbar/panels/settings.html | 2 +- .../debug_toolbar/panels/signals.html | 2 +- .../templates/debug_toolbar/panels/sql.html | 2 +- .../debug_toolbar/panels/sql_explain.html | 2 +- .../debug_toolbar/panels/sql_profile.html | 2 +- .../debug_toolbar/panels/sql_select.html | 2 +- .../debug_toolbar/panels/staticfiles.html | 2 +- .../templates/debug_toolbar/panels/timer.html | 2 +- .../debug_toolbar/panels/versions.html | 2 +- .../templatetags/debug_toolbar_compat.py | 13 --- docs/changes.rst | 8 +- example/README.rst | 2 +- example/settings.py | 13 ++- setup.py | 2 +- tests/panels/test_redirects.py | 9 +- tests/panels/test_sql.py | 6 +- tests/settings.py | 8 ++ tests/test_integration.py | 15 ++-- tox.ini | 6 +- 28 files changed, 90 insertions(+), 167 deletions(-) delete mode 100644 debug_toolbar/templatetags/debug_toolbar_compat.py diff --git a/.travis.yml b/.travis.yml index 93759b786..8e7db0086 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ python: - "3.4" - "3.5" env: - - DJANGO="Django>=1.7.0,<1.8.0" - DJANGO="Django>=1.8.0,<1.9.0" - DJANGO="Django>=1.9.0,<1.10.0" - DJANGO="Django<1.11.0" @@ -21,8 +20,6 @@ matrix: env: DJANGO="Django<1.11.0" - python: "3.3" env: DJANGO="Django<1.11.0" - - python: "3.5" - env: DJANGO="Django>=1.7.0,<1.8.0" - python: "3.5" env: DJANGO="Django>=1.8.0,<1.9.0" install: diff --git a/README.rst b/README.rst index e9fce0080..9426770d0 100644 --- a/README.rst +++ b/README.rst @@ -19,7 +19,7 @@ Here's a screenshot of the toolbar in action: In addition to the built-in panels, a number of third-party panels are contributed by the community. -The current version of the Debug Toolbar is 1.4. It works on Django ≥ 1.7. +The current version of the Debug Toolbar is 1.5. It works on Django ≥ 1.8. Documentation, including installation and configuration instructions, is available at https://django-debug-toolbar.readthedocs.io/. diff --git a/debug_toolbar/compat.py b/debug_toolbar/compat.py index a38232c41..11b4268ee 100644 --- a/debug_toolbar/compat.py +++ b/debug_toolbar/compat.py @@ -5,61 +5,8 @@ debug_toolbar. """ -from django.conf import settings -from django.core.exceptions import ImproperlyConfigured - try: from django.template.base import linebreak_iter # NOQA except ImportError: # Django < 1.9 from django.views.debug import linebreak_iter # NOQA -try: - from django.template.engine import Engine -except ImportError: # Django < 1.8 - Engine = None - from django.template.context import get_standard_processors # NOQA - from django.template.loader import find_template_loader # NOQA - - -def get_template_dirs(): - """Compatibility method to fetch the template directories.""" - if Engine: - try: - engine = Engine.get_default() - except ImproperlyConfigured: - template_dirs = [] - else: - template_dirs = engine.dirs - else: # Django < 1.8 - template_dirs = settings.TEMPLATE_DIRS - return template_dirs - - -def get_template_loaders(): - """Compatibility method to fetch the template loaders.""" - if Engine: - try: - engine = Engine.get_default() - except ImproperlyConfigured: - loaders = [] - else: - loaders = engine.template_loaders - else: # Django < 1.8 - loaders = [ - find_template_loader(loader_name) - for loader_name in settings.TEMPLATE_LOADERS] - return loaders - - -def get_template_context_processors(): - """Compatibility method to fetch the template context processors.""" - if Engine: - try: - engine = Engine.get_default() - except ImproperlyConfigured: - context_processors = [] - else: - context_processors = engine.template_context_processors - else: # Django < 1.8 - context_processors = get_standard_processors() - return context_processors diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index 76ce6898e..d8e05a991 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -16,9 +16,6 @@ from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ -from debug_toolbar.compat import ( - get_template_context_processors, get_template_dirs, -) from debug_toolbar.panels import Panel from debug_toolbar.panels.sql.tracking import SQLQueryTriggered, recording from debug_toolbar.panels.templates import views @@ -37,58 +34,32 @@ # Monkey-patch to store items added by template context processors. The # overhead is sufficiently small to justify enabling it unconditionally. -if django.VERSION[:2] < (1, 8): - - def _request_context___init__( - self, request, dict_=None, processors=None, current_app=None, - use_l10n=None, use_tz=None): - Context.__init__( - self, dict_, current_app=current_app, - use_l10n=use_l10n, use_tz=use_tz) - if processors is None: - processors = () - else: - processors = tuple(processors) - self.context_processors = OrderedDict() - updates = dict() - std_processors = get_template_context_processors() - for processor in std_processors + processors: - name = '%s.%s' % (processor.__module__, processor.__name__) - context = processor(request) - self.context_processors[name] = context - updates.update(context) - self.update(updates) - - RequestContext.__init__ = _request_context___init__ - -else: - - @contextmanager - def _request_context_bind_template(self, template): - if self.template is not None: - raise RuntimeError("Context is already bound to a template") - - self.template = template - # Set context processors according to the template engine's settings. - processors = (template.engine.template_context_processors + - self._processors) - self.context_processors = OrderedDict() - updates = {} - for processor in processors: - name = '%s.%s' % (processor.__module__, processor.__name__) - context = processor(self.request) - self.context_processors[name] = context - updates.update(context) - self.dicts[self._processors_index] = updates - - try: - yield - finally: - self.template = None - # Unset context processors. - self.dicts[self._processors_index] = {} - - RequestContext.bind_template = _request_context_bind_template +@contextmanager +def _request_context_bind_template(self, template): + if self.template is not None: + raise RuntimeError("Context is already bound to a template") + + self.template = template + # Set context processors according to the template engine's settings. + processors = (template.engine.template_context_processors + + self._processors) + self.context_processors = OrderedDict() + updates = {} + for processor in processors: + name = '%s.%s' % (processor.__module__, processor.__name__) + context = processor(self.request) + self.context_processors[name] = context + updates.update(context) + self.dicts[self._processors_index] = updates + + try: + yield + finally: + self.template = None + # Unset context processors. + self.dicts[self._processors_index] = {} + +RequestContext.bind_template = _request_context_bind_template class TemplatesPanel(Panel): @@ -199,13 +170,13 @@ def generate_stats(self, request, response): info['context'] = '\n'.join(context_list) template_context.append(info) - # Fetch context_processors from any template + # Fetch context_processors/template_dirs from any template if self.templates: context_processors = self.templates[0]['context_processors'] + template_dirs = self.templates[0]['template'].engine.dirs else: context_processors = None - - template_dirs = get_template_dirs() + template_dirs = [] self.record_stats({ 'templates': template_context, diff --git a/debug_toolbar/panels/templates/views.py b/debug_toolbar/panels/templates/views.py index eb3fcf8cd..dbd52e5b0 100644 --- a/debug_toolbar/panels/templates/views.py +++ b/debug_toolbar/panels/templates/views.py @@ -5,7 +5,7 @@ from django.template import TemplateDoesNotExist from django.utils.safestring import mark_safe -from debug_toolbar.compat import get_template_loaders +from django.template.engine import Engine def template_source(request): @@ -18,7 +18,7 @@ def template_source(request): return HttpResponseBadRequest('"template" key is required') final_loaders = [] - loaders = get_template_loaders() + loaders = Engine.get_default().template_loaders for loader in loaders: if loader is not None: diff --git a/debug_toolbar/templates/debug_toolbar/panels/cache.html b/debug_toolbar/templates/debug_toolbar/panels/cache.html index e54193807..014e5f621 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/cache.html +++ b/debug_toolbar/templates/debug_toolbar/panels/cache.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %}

{% trans "Summary" %}

diff --git a/debug_toolbar/templates/debug_toolbar/panels/headers.html b/debug_toolbar/templates/debug_toolbar/panels/headers.html index a99e7d18b..6b43e94a4 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/headers.html +++ b/debug_toolbar/templates/debug_toolbar/panels/headers.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %}

{% trans "Request headers" %}

diff --git a/debug_toolbar/templates/debug_toolbar/panels/logging.html b/debug_toolbar/templates/debug_toolbar/panels/logging.html index 21d0c2e77..3908f4fea 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/logging.html +++ b/debug_toolbar/templates/debug_toolbar/panels/logging.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %} {% if records %}
diff --git a/debug_toolbar/templates/debug_toolbar/panels/request.html b/debug_toolbar/templates/debug_toolbar/panels/request.html index c7d5ff9b7..1cea669cb 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/request.html +++ b/debug_toolbar/templates/debug_toolbar/panels/request.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %}

{% trans "View information" %}

diff --git a/debug_toolbar/templates/debug_toolbar/panels/settings.html b/debug_toolbar/templates/debug_toolbar/panels/settings.html index 62c42bfeb..f6b5afe8f 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/settings.html +++ b/debug_toolbar/templates/debug_toolbar/panels/settings.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %}
diff --git a/debug_toolbar/templates/debug_toolbar/panels/signals.html b/debug_toolbar/templates/debug_toolbar/panels/signals.html index 6ddbc7753..ac32f3735 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/signals.html +++ b/debug_toolbar/templates/debug_toolbar/panels/signals.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %}
diff --git a/debug_toolbar/templates/debug_toolbar/panels/sql.html b/debug_toolbar/templates/debug_toolbar/panels/sql.html index afbc6b229..8b40f4592 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/sql.html +++ b/debug_toolbar/templates/debug_toolbar/panels/sql.html @@ -1,4 +1,4 @@ -{% load i18n l10n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %} +{% load i18n l10n %}{% load static from staticfiles %}
diff --git a/debug_toolbar/templates/debug_toolbar/panels/versions.html b/debug_toolbar/templates/debug_toolbar/panels/versions.html index 3f3052900..2c614f11c 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/versions.html +++ b/debug_toolbar/templates/debug_toolbar/panels/versions.html @@ -1,4 +1,4 @@ -{% load i18n %}{% load cycle from debug_toolbar_compat %} +{% load i18n %}
diff --git a/debug_toolbar/templatetags/debug_toolbar_compat.py b/debug_toolbar/templatetags/debug_toolbar_compat.py deleted file mode 100644 index 80f85b788..000000000 --- a/debug_toolbar/templatetags/debug_toolbar_compat.py +++ /dev/null @@ -1,13 +0,0 @@ -import django -from django.template import Library - -if django.VERSION >= (1, 8): - from django.template.defaulttags import cycle -else: - from django.templatetags.future import cycle - - -register = Library() - - -cycle = register.tag(cycle) diff --git a/docs/changes.rst b/docs/changes.rst index b7b8cc1c1..ffb175dfb 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -1,11 +1,15 @@ Change log ========== +1.5 +--- + +This version is compatible with Django 1.10 and requires Django 1.8 or later. + 1.4 --- -This version is compatible with Django 1.9 release and requires -Django 1.7 or later. +This version is compatible with Django 1.9 and requires Django 1.7 or later. New features ~~~~~~~~~~~~ diff --git a/example/README.rst b/example/README.rst index f6f5b7147..886ee0655 100644 --- a/example/README.rst +++ b/example/README.rst @@ -22,7 +22,7 @@ the debug toolbar, ie. the directory that contains ``example/``. Before running the example for the first time, you must create a database:: - $ PYTHONPATH=. django-admin syncdb --settings=example.settings + $ PYTHONPATH=. django-admin migrate --settings=example.settings Then you can use the following command to run the example:: diff --git a/example/settings.py b/example/settings.py index 7b0531fb7..7169ec430 100644 --- a/example/settings.py +++ b/example/settings.py @@ -11,8 +11,6 @@ DEBUG = True -TEMPLATE_DEBUG = True - # Application definition @@ -38,7 +36,16 @@ STATIC_URL = '/static/' -TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'example', 'templates')] +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'DIRS': [os.path.join(BASE_DIR, 'example', 'templates')], + 'OPTIONS': { + 'debug': True, + }, + }, +] WSGI_APPLICATION = 'example.wsgi.application' diff --git a/setup.py b/setup.py index 37dcd0264..ed9c17e2b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ license='BSD', packages=find_packages(exclude=('tests.*', 'tests', 'example')), install_requires=[ - 'Django>=1.7', + 'Django>=1.8', 'sqlparse', ], include_package_data=True, diff --git a/tests/panels/test_redirects.py b/tests/panels/test_redirects.py index beacabcbe..57ebb490d 100644 --- a/tests/panels/test_redirects.py +++ b/tests/panels/test_redirects.py @@ -1,5 +1,7 @@ from __future__ import absolute_import, unicode_literals +import copy + from django.conf import settings from django.http import HttpResponse from django.test.utils import override_settings @@ -35,11 +37,10 @@ def test_redirect(self): self.assertContains(response, 'http://somewhere/else/') def test_redirect_with_broken_context_processor(self): - context_processors = list(settings.TEMPLATE_CONTEXT_PROCESSORS) + [ - 'tests.context_processors.broken', - ] + TEMPLATES = copy.deepcopy(settings.TEMPLATES) + TEMPLATES[0]['OPTIONS']['context_processors'] = ['tests.context_processors.broken'] - with self.settings(TEMPLATE_CONTEXT_PROCESSORS=context_processors): + with self.settings(TEMPLATES=TEMPLATES): redirect = HttpResponse(status=302) redirect['Location'] = 'http://somewhere/else/' response = self.panel.process_response(self.request, redirect) diff --git a/tests/panels/test_sql.py b/tests/panels/test_sql.py index 543188da1..993583201 100644 --- a/tests/panels/test_sql.py +++ b/tests/panels/test_sql.py @@ -110,8 +110,10 @@ def test_disable_stacktraces(self): # ensure the stacktrace is empty self.assertEqual([], query[1]['stacktrace']) - @override_settings(DEBUG=True, TEMPLATE_DEBUG=True, - TEMPLATE_LOADERS=('tests.loaders.LoaderWithSQL',)) + @override_settings(DEBUG=True, TEMPLATES=[{ + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'OPTIONS': {'debug': True, 'loaders': ['tests.loaders.LoaderWithSQL']}, + }]) def test_regression_infinite_recursion(self): """ Test case for when the template loader runs a SQL query that causes diff --git a/tests/settings.py b/tests/settings.py index 8cbe6c96c..dddb88a71 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -41,6 +41,14 @@ ROOT_URLCONF = 'tests.urls' +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'OPTIONS': {}, + }, +] + STATIC_ROOT = os.path.join(BASE_DIR, 'tests', 'static') STATIC_URL = '/static/' diff --git a/tests/test_integration.py b/tests/test_integration.py index 0837c95fc..d2d9f955b 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -164,12 +164,15 @@ def test_expired_store(self): lambda selenium: version_panel.find_element_by_tag_name('p')) self.assertIn("Data for this panel isn't available anymore.", error.text) - @override_settings(TEMPLATE_LOADERS=[( - 'django.template.loaders.cached.Loader', ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - ), - )]) + @override_settings(DEBUG=True, TEMPLATES=[{ + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'OPTIONS': {'loaders': [( + 'django.template.loaders.cached.Loader', ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + ) + )]}, + }]) def test_django_cached_template_loader(self): self.selenium.get(self.live_server_url + '/regular/basic/') version_panel = self.selenium.find_element_by_id('TemplatesPanel') diff --git a/tox.ini b/tox.ini index ce585280b..8491cc871 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{27,32,33,34}-django{17,18}, + py{27,32,33,34}-django18, py{27,34,35}-django{19,110}, flake8, isort @@ -14,10 +14,6 @@ basepython = py35: python3.5 commands = make test deps = - django14: Django>=1.4,<1.5 - django15: Django>=1.5,<1.6 - django16: Django>=1.6,<1.7 - django17: Django>=1.7,<1.8 django18: Django>=1.8,<1.9 django19: Django>=1.9,<1.10 django110: Django<1.11