Skip to content

Commit 7534d5c

Browse files
committed
Merge pull request #832 from claudep/drop17
Dropped Django 1.7 support
2 parents e862feb + 6390279 commit 7534d5c

28 files changed

+90
-167
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ python:
77
- "3.4"
88
- "3.5"
99
env:
10-
- DJANGO="Django>=1.7.0,<1.8.0"
1110
- DJANGO="Django>=1.8.0,<1.9.0"
1211
- DJANGO="Django>=1.9.0,<1.10.0"
1312
- DJANGO="Django<1.11.0"
@@ -21,8 +20,6 @@ matrix:
2120
env: DJANGO="Django<1.11.0"
2221
- python: "3.3"
2322
env: DJANGO="Django<1.11.0"
24-
- python: "3.5"
25-
env: DJANGO="Django>=1.7.0,<1.8.0"
2623
- python: "3.5"
2724
env: DJANGO="Django>=1.8.0,<1.9.0"
2825
install:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here's a screenshot of the toolbar in action:
1919
In addition to the built-in panels, a number of third-party panels are
2020
contributed by the community.
2121

22-
The current version of the Debug Toolbar is 1.4. It works on Django ≥ 1.7.
22+
The current version of the Debug Toolbar is 1.5. It works on Django ≥ 1.8.
2323

2424
Documentation, including installation and configuration instructions, is
2525
available at https://django-debug-toolbar.readthedocs.io/.

debug_toolbar/compat.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,8 @@
55
debug_toolbar.
66
"""
77

8-
from django.conf import settings
9-
from django.core.exceptions import ImproperlyConfigured
10-
118
try:
129
from django.template.base import linebreak_iter # NOQA
1310
except ImportError: # Django < 1.9
1411
from django.views.debug import linebreak_iter # NOQA
1512

16-
try:
17-
from django.template.engine import Engine
18-
except ImportError: # Django < 1.8
19-
Engine = None
20-
from django.template.context import get_standard_processors # NOQA
21-
from django.template.loader import find_template_loader # NOQA
22-
23-
24-
def get_template_dirs():
25-
"""Compatibility method to fetch the template directories."""
26-
if Engine:
27-
try:
28-
engine = Engine.get_default()
29-
except ImproperlyConfigured:
30-
template_dirs = []
31-
else:
32-
template_dirs = engine.dirs
33-
else: # Django < 1.8
34-
template_dirs = settings.TEMPLATE_DIRS
35-
return template_dirs
36-
37-
38-
def get_template_loaders():
39-
"""Compatibility method to fetch the template loaders."""
40-
if Engine:
41-
try:
42-
engine = Engine.get_default()
43-
except ImproperlyConfigured:
44-
loaders = []
45-
else:
46-
loaders = engine.template_loaders
47-
else: # Django < 1.8
48-
loaders = [
49-
find_template_loader(loader_name)
50-
for loader_name in settings.TEMPLATE_LOADERS]
51-
return loaders
52-
53-
54-
def get_template_context_processors():
55-
"""Compatibility method to fetch the template context processors."""
56-
if Engine:
57-
try:
58-
engine = Engine.get_default()
59-
except ImproperlyConfigured:
60-
context_processors = []
61-
else:
62-
context_processors = engine.template_context_processors
63-
else: # Django < 1.8
64-
context_processors = get_standard_processors()
65-
return context_processors

debug_toolbar/panels/templates/panel.py

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
from django.utils.encoding import force_text
1717
from django.utils.translation import ugettext_lazy as _
1818

19-
from debug_toolbar.compat import (
20-
get_template_context_processors, get_template_dirs,
21-
)
2219
from debug_toolbar.panels import Panel
2320
from debug_toolbar.panels.sql.tracking import SQLQueryTriggered, recording
2421
from debug_toolbar.panels.templates import views
@@ -37,58 +34,32 @@
3734
# Monkey-patch to store items added by template context processors. The
3835
# overhead is sufficiently small to justify enabling it unconditionally.
3936

40-
if django.VERSION[:2] < (1, 8):
41-
42-
def _request_context___init__(
43-
self, request, dict_=None, processors=None, current_app=None,
44-
use_l10n=None, use_tz=None):
45-
Context.__init__(
46-
self, dict_, current_app=current_app,
47-
use_l10n=use_l10n, use_tz=use_tz)
48-
if processors is None:
49-
processors = ()
50-
else:
51-
processors = tuple(processors)
52-
self.context_processors = OrderedDict()
53-
updates = dict()
54-
std_processors = get_template_context_processors()
55-
for processor in std_processors + processors:
56-
name = '%s.%s' % (processor.__module__, processor.__name__)
57-
context = processor(request)
58-
self.context_processors[name] = context
59-
updates.update(context)
60-
self.update(updates)
61-
62-
RequestContext.__init__ = _request_context___init__
63-
64-
else:
65-
66-
@contextmanager
67-
def _request_context_bind_template(self, template):
68-
if self.template is not None:
69-
raise RuntimeError("Context is already bound to a template")
70-
71-
self.template = template
72-
# Set context processors according to the template engine's settings.
73-
processors = (template.engine.template_context_processors +
74-
self._processors)
75-
self.context_processors = OrderedDict()
76-
updates = {}
77-
for processor in processors:
78-
name = '%s.%s' % (processor.__module__, processor.__name__)
79-
context = processor(self.request)
80-
self.context_processors[name] = context
81-
updates.update(context)
82-
self.dicts[self._processors_index] = updates
83-
84-
try:
85-
yield
86-
finally:
87-
self.template = None
88-
# Unset context processors.
89-
self.dicts[self._processors_index] = {}
90-
91-
RequestContext.bind_template = _request_context_bind_template
37+
@contextmanager
38+
def _request_context_bind_template(self, template):
39+
if self.template is not None:
40+
raise RuntimeError("Context is already bound to a template")
41+
42+
self.template = template
43+
# Set context processors according to the template engine's settings.
44+
processors = (template.engine.template_context_processors +
45+
self._processors)
46+
self.context_processors = OrderedDict()
47+
updates = {}
48+
for processor in processors:
49+
name = '%s.%s' % (processor.__module__, processor.__name__)
50+
context = processor(self.request)
51+
self.context_processors[name] = context
52+
updates.update(context)
53+
self.dicts[self._processors_index] = updates
54+
55+
try:
56+
yield
57+
finally:
58+
self.template = None
59+
# Unset context processors.
60+
self.dicts[self._processors_index] = {}
61+
62+
RequestContext.bind_template = _request_context_bind_template
9263

9364

9465
class TemplatesPanel(Panel):
@@ -199,13 +170,13 @@ def generate_stats(self, request, response):
199170
info['context'] = '\n'.join(context_list)
200171
template_context.append(info)
201172

202-
# Fetch context_processors from any template
173+
# Fetch context_processors/template_dirs from any template
203174
if self.templates:
204175
context_processors = self.templates[0]['context_processors']
176+
template_dirs = self.templates[0]['template'].engine.dirs
205177
else:
206178
context_processors = None
207-
208-
template_dirs = get_template_dirs()
179+
template_dirs = []
209180

210181
self.record_stats({
211182
'templates': template_context,

debug_toolbar/panels/templates/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.template import TemplateDoesNotExist
66
from django.utils.safestring import mark_safe
77

8-
from debug_toolbar.compat import get_template_loaders
8+
from django.template.engine import Engine
99

1010

1111
def template_source(request):
@@ -18,7 +18,7 @@ def template_source(request):
1818
return HttpResponseBadRequest('"template" key is required')
1919

2020
final_loaders = []
21-
loaders = get_template_loaders()
21+
loaders = Engine.get_default().template_loaders
2222

2323
for loader in loaders:
2424
if loader is not None:

debug_toolbar/templates/debug_toolbar/panels/cache.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22
<h4>{% trans "Summary" %}</h4>
33
<table>
44
<thead>

debug_toolbar/templates/debug_toolbar/panels/headers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22

33
<h4>{% trans "Request headers" %}</h4>
44

debug_toolbar/templates/debug_toolbar/panels/logging.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22
{% if records %}
33
<table>
44
<thead>

debug_toolbar/templates/debug_toolbar/panels/request.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22

33
<h4>{% trans "View information" %}</h4>
44
<table>

debug_toolbar/templates/debug_toolbar/panels/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22
<table>
33
<thead>
44
<tr>

debug_toolbar/templates/debug_toolbar/panels/signals.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22
<table>
33
<thead>
44
<tr>

debug_toolbar/templates/debug_toolbar/panels/sql.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n l10n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
1+
{% load i18n l10n %}{% load static from staticfiles %}
22
<div class="djdt-clearfix">
33
<ul class="djdt-stats">
44
{% for alias, info in databases %}

debug_toolbar/templates/debug_toolbar/panels/sql_explain.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
1+
{% load i18n %}{% load static from staticfiles %}
22
<div class="djDebugPanelTitle">
33
<a class="djDebugClose djDebugBack" href=""></a>
44
<h3>{% trans "SQL explained" %}</h3>

debug_toolbar/templates/debug_toolbar/panels/sql_profile.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
1+
{% load i18n %}{% load static from staticfiles %}
22
<div class="djDebugPanelTitle">
33
<a class="djDebugClose djDebugBack" href=""></a>
44
<h3>{% trans "SQL profiled" %}</h3>

debug_toolbar/templates/debug_toolbar/panels/sql_select.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
1+
{% load i18n %}{% load static from staticfiles %}
22
<div class="djDebugPanelTitle">
33
<a class="djDebugClose djDebugBack" href=""></a>
44
<h3>{% trans "SQL selected" %}</h3>

debug_toolbar/templates/debug_toolbar/panels/staticfiles.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles%}
1+
{% load i18n %}{% load static from staticfiles%}
22

33
<h4>{% blocktrans count staticfiles_dirs|length as dirs_count %}Static file path{% plural %}Static file paths{% endblocktrans %}</h4>
44
{% if staticfiles_dirs %}

debug_toolbar/templates/debug_toolbar/panels/timer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
1+
{% load i18n %}{% load static from staticfiles %}
22
<h4>{% trans "Resource usage" %}</h4>
33
<table>
44
<colgroup>

debug_toolbar/templates/debug_toolbar/panels/versions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load i18n %}{% load cycle from debug_toolbar_compat %}
1+
{% load i18n %}
22
<table>
33
<thead>
44
<tr>

debug_toolbar/templatetags/debug_toolbar_compat.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/changes.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
Change log
22
==========
33

4+
1.5
5+
---
6+
7+
This version is compatible with Django 1.10 and requires Django 1.8 or later.
8+
49
1.4
510
---
611

7-
This version is compatible with Django 1.9 release and requires
8-
Django 1.7 or later.
12+
This version is compatible with Django 1.9 and requires Django 1.7 or later.
913

1014
New features
1115
~~~~~~~~~~~~

example/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ the debug toolbar, ie. the directory that contains ``example/``.
2222

2323
Before running the example for the first time, you must create a database::
2424

25-
$ PYTHONPATH=. django-admin syncdb --settings=example.settings
25+
$ PYTHONPATH=. django-admin migrate --settings=example.settings
2626

2727
Then you can use the following command to run the example::
2828

example/settings.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
DEBUG = True
1313

14-
TEMPLATE_DEBUG = True
15-
1614

1715
# Application definition
1816

@@ -38,7 +36,16 @@
3836

3937
STATIC_URL = '/static/'
4038

41-
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'example', 'templates')]
39+
TEMPLATES = [
40+
{
41+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
42+
'APP_DIRS': True,
43+
'DIRS': [os.path.join(BASE_DIR, 'example', 'templates')],
44+
'OPTIONS': {
45+
'debug': True,
46+
},
47+
},
48+
]
4249

4350
WSGI_APPLICATION = 'example.wsgi.application'
4451

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
license='BSD',
1616
packages=find_packages(exclude=('tests.*', 'tests', 'example')),
1717
install_requires=[
18-
'Django>=1.7',
18+
'Django>=1.8',
1919
'sqlparse',
2020
],
2121
include_package_data=True,

tests/panels/test_redirects.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import, unicode_literals
22

3+
import copy
4+
35
from django.conf import settings
46
from django.http import HttpResponse
57
from django.test.utils import override_settings
@@ -35,11 +37,10 @@ def test_redirect(self):
3537
self.assertContains(response, 'http://somewhere/else/')
3638

3739
def test_redirect_with_broken_context_processor(self):
38-
context_processors = list(settings.TEMPLATE_CONTEXT_PROCESSORS) + [
39-
'tests.context_processors.broken',
40-
]
40+
TEMPLATES = copy.deepcopy(settings.TEMPLATES)
41+
TEMPLATES[0]['OPTIONS']['context_processors'] = ['tests.context_processors.broken']
4142

42-
with self.settings(TEMPLATE_CONTEXT_PROCESSORS=context_processors):
43+
with self.settings(TEMPLATES=TEMPLATES):
4344
redirect = HttpResponse(status=302)
4445
redirect['Location'] = 'http://somewhere/else/'
4546
response = self.panel.process_response(self.request, redirect)

0 commit comments

Comments
 (0)