Skip to content

Commit 4ff29f1

Browse files
committed
Drop support for Django < 1.11 and remove workarounds
Per Django's recommendation, now that django-debug-toolbar supports 2.0, it should drop support for Django < 1.11 to ease maintenance and compatibility across Django versions. So long as no deprecation warnings are produced, django-debug-toolbar should remain forward compatible with the next Django version. For more details, see the Django docs: https://docs.djangoproject.com/en/2.0/releases/2.0/#third-party-library-support-for-older-version-of-django > Third-party library support for older version of Django > > Following the release of Django 2.0, we suggest that third-party app authors > drop support for all versions of Django prior to 1.11. At that time, you > should be able to run your package’s tests using python -Wd so that > deprecation warnings do appear. After making the deprecation warning fixes, > your app should be compatible with Django 2.0. Those wishing to continue using an older Django can pin the version django-debug-toolbar.
1 parent b7672d9 commit 4ff29f1

File tree

17 files changed

+27
-157
lines changed

17 files changed

+27
-157
lines changed

.travis.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,6 @@ sudo: false
33
cache: pip
44
matrix:
55
include:
6-
- python: 2.7
7-
env: TOXENV=py27-dj18
8-
- python: 3.3
9-
env: TOXENV=py33-dj18
10-
- python: 3.4
11-
env: TOXENV=py34-dj18
12-
- python: 2.7
13-
env: TOXENV=py27-dj19
14-
- python: 3.4
15-
env: TOXENV=py34-dj19
16-
- python: 3.5
17-
env: TOXENV=py35-dj19
18-
- python: 2.7
19-
env: TOXENV=py27-dj110
20-
- python: 3.4
21-
env: TOXENV=py34-dj110
22-
- python: 3.5
23-
env: TOXENV=py35-dj110
246
- python: 2.7
257
env: TOXENV=py27-dj111
268
- python: 3.4

README.rst

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

34-
The current version of the Debug Toolbar is 1.9. It works on Django ≥ 1.8.
34+
The current version of the Debug Toolbar is 1.9. It works on Django ≥ 1.11.
3535

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

debug_toolbar/__init__.py

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

3-
import django
4-
53
__all__ = ['VERSION']
64

75

@@ -14,9 +12,6 @@
1412

1513
# Code that discovers files or modules in INSTALLED_APPS imports this module.
1614

17-
if django.VERSION < (1, 9):
18-
urls = 'debug_toolbar.toolbar', 'djdt', 'djdt'
19-
else:
20-
urls = 'debug_toolbar.toolbar', 'djdt'
15+
urls = 'debug_toolbar.toolbar', 'djdt'
2116

2217
default_app_config = 'debug_toolbar.apps.DebugToolbarConfig'

debug_toolbar/compat.py

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

debug_toolbar/middleware.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,14 @@
99

1010
from django.conf import settings
1111
from django.utils import six
12+
from django.utils.deprecation import MiddlewareMixin
1213
from django.utils.encoding import force_text
1314
from django.utils.lru_cache import lru_cache
1415
from django.utils.module_loading import import_string
1516

1617
from debug_toolbar import settings as dt_settings
1718
from debug_toolbar.toolbar import DebugToolbar
1819

19-
try:
20-
from django.utils.deprecation import MiddlewareMixin
21-
except ImportError: # Django < 1.10
22-
# Works perfectly for everyone using MIDDLEWARE_CLASSES
23-
MiddlewareMixin = object
24-
25-
2620
_HTML_TYPES = ('text/html', 'application/xhtml+xml')
2721

2822

debug_toolbar/panels/cache.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import time
66
from collections import OrderedDict
77

8-
import django
98
from django.conf import settings
109
from django.core import cache
1110
from django.core.cache import CacheHandler, caches as original_caches
@@ -20,9 +19,6 @@
2019
get_stack, get_template_info, render_stacktrace, tidy_stacktrace,
2120
)
2221

23-
if django.VERSION[:2] < (1, 9):
24-
from django.core.cache import get_cache as original_get_cache
25-
2622
cache_called = Signal(providing_args=[
2723
"time_taken", "name", "return_value", "args", "kwargs", "trace"])
2824

@@ -121,24 +117,12 @@ def decr_version(self, *args, **kwargs):
121117
return self.cache.decr_version(*args, **kwargs)
122118

123119

124-
if django.VERSION[:2] < (1, 9):
125-
def get_cache(*args, **kwargs):
126-
return CacheStatTracker(original_get_cache(*args, **kwargs))
127-
128-
129120
class CacheHandlerPatch(CacheHandler):
130121
def __getitem__(self, alias):
131122
actual_cache = super(CacheHandlerPatch, self).__getitem__(alias)
132123
return CacheStatTracker(actual_cache)
133124

134125

135-
# Must monkey patch the middleware's cache module as well in order to
136-
# cover per-view level caching. This needs to be monkey patched outside
137-
# of the enable_instrumentation method since the django's
138-
# decorator_from_middleware_with_args will store the cache from core.caches
139-
# when it wraps the view.
140-
if django.VERSION[:2] < (1, 9):
141-
middleware_cache.get_cache = get_cache
142126
middleware_cache.caches = CacheHandlerPatch()
143127

144128

@@ -219,16 +203,12 @@ def title(self):
219203
count) % dict(count=count)
220204

221205
def enable_instrumentation(self):
222-
if django.VERSION[:2] < (1, 9):
223-
cache.get_cache = get_cache
224206
if isinstance(middleware_cache.caches, CacheHandlerPatch):
225207
cache.caches = middleware_cache.caches
226208
else:
227209
cache.caches = CacheHandlerPatch()
228210

229211
def disable_instrumentation(self):
230-
if django.VERSION[:2] < (1, 9):
231-
cache.get_cache = original_get_cache
232212
cache.caches = original_caches
233213
# While it can be restored to the original, any views that were
234214
# wrapped with the cache_page decorator will continue to use a

debug_toolbar/panels/request.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import absolute_import, unicode_literals
22

33
from django.http import Http404
4+
from django.urls import resolve
45
from django.utils.encoding import force_text
56
from django.utils.translation import ugettext_lazy as _
67

78
from debug_toolbar.panels import Panel
89
from debug_toolbar.utils import get_name_from_obj
910

10-
try:
11-
from django.urls import resolve
12-
except ImportError: # Django < 1.10 pragma: no cover
13-
from django.core.urlresolvers import resolve
14-
1511

1612
class RequestPanel(Panel):
1713
"""

debug_toolbar/panels/templates/views.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
from django.core import signing
44
from django.http import HttpResponseBadRequest
5-
from django.template import TemplateDoesNotExist
5+
from django.template import Origin, TemplateDoesNotExist
66
from django.template.engine import Engine
77
from django.template.response import SimpleTemplateResponse
88
from django.utils.safestring import mark_safe
99

1010
from debug_toolbar.decorators import require_show_toolbar
1111

12-
try:
13-
from django.template import Origin
14-
except ImportError:
15-
Origin = None
16-
1712

1813
@require_show_toolbar
1914
def template_source(request):
@@ -44,19 +39,12 @@ def template_source(request):
4439
final_loaders.append(loader)
4540

4641
for loader in final_loaders:
47-
if Origin: # django>=1.9
48-
origin = Origin(template_origin_name)
49-
try:
50-
source = loader.get_contents(origin)
51-
break
52-
except TemplateDoesNotExist:
53-
pass
54-
else: # django<1.9
55-
try:
56-
source, _ = loader.load_template_source(template_name)
57-
break
58-
except TemplateDoesNotExist:
59-
pass
42+
origin = Origin(template_origin_name)
43+
try:
44+
source = loader.get_contents(origin)
45+
break
46+
except TemplateDoesNotExist:
47+
pass
6048
else:
6149
source = "Template Does Not Exist: %s" % (template_origin_name,)
6250

debug_toolbar/utils.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from django.utils.safestring import mark_safe
1717

1818
from debug_toolbar import settings as dt_settings
19-
from debug_toolbar.compat import linebreak_iter
2019

2120
try:
2221
import threading
@@ -116,15 +115,8 @@ def get_template_info():
116115

117116

118117
def get_template_context(node, context, context_lines=3):
119-
source = getattr(node, 'source', None)
120-
# In Django 1.9 template Node does not have source property, Origin does
121-
# not reload method, so we extract contextual information from exception
122-
# info.
123-
if source:
124-
line, source_lines, name = get_template_source_from_source(source)
125-
else:
126-
line, source_lines, name = get_template_source_from_exception_info(
127-
node, context)
118+
line, source_lines, name = get_template_source_from_exception_info(
119+
node, context)
128120
debug_context = []
129121
start = max(1, line - context_lines)
130122
end = line + 1 + context_lines
@@ -143,26 +135,6 @@ def get_template_context(node, context, context_lines=3):
143135
}
144136

145137

146-
def get_template_source_from_source(source):
147-
line = 0
148-
upto = 0
149-
source_lines = []
150-
# before = during = after = ""
151-
152-
origin, (start, end) = source
153-
template_source = origin.reload()
154-
155-
for num, next in enumerate(linebreak_iter(template_source)):
156-
if start >= upto and end <= next:
157-
line = num
158-
# before = template_source[upto:start]
159-
# during = template_source[start:end]
160-
# after = template_source[end:next]
161-
source_lines.append((num, template_source[upto:next]))
162-
upto = next
163-
return line, source_lines, origin.name
164-
165-
166138
def get_template_source_from_exception_info(node, context):
167139
exception_info = context.template.get_exception_info(
168140
Exception('DDT'), node.token)

docs/changes.rst

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

4+
UNRELEASED
5+
----------
6+
7+
* Removed support for Django < 1.11.
8+
49
1.9.1 (2017-11-15)
510
------------------
611

setup.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
license='BSD',
1818
packages=find_packages(exclude=('tests.*', 'tests', 'example')),
1919
install_requires=[
20-
'Django>=1.8',
20+
'Django>=1.11',
2121
'sqlparse>=0.2.0',
2222
],
2323
include_package_data=True,
@@ -26,9 +26,6 @@
2626
'Development Status :: 5 - Production/Stable',
2727
'Environment :: Web Environment',
2828
'Framework :: Django',
29-
'Framework :: Django :: 1.8',
30-
'Framework :: Django :: 1.9',
31-
'Framework :: Django :: 1.10',
3229
'Framework :: Django :: 1.11',
3330
'Framework :: Django :: 2.0',
3431
'Intended Audience :: Developers',
@@ -38,7 +35,6 @@
3835
'Programming Language :: Python :: 2',
3936
'Programming Language :: Python :: 2.7',
4037
'Programming Language :: Python :: 3',
41-
'Programming Language :: Python :: 3.3',
4238
'Programming Language :: Python :: 3.4',
4339
'Programming Language :: Python :: 3.5',
4440
'Programming Language :: Python :: 3.6',

tests/loaders.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import django
21
from django.contrib.auth.models import User
32
from django.template.loaders.app_directories import Loader
43

54

65
class LoaderWithSQL(Loader):
7-
8-
if django.VERSION[:2] >= (1, 9):
9-
def get_template(self, *args, **kwargs):
10-
# Force the template loader to run some SQL. Simulates a CMS.
11-
User.objects.all().count()
12-
return super(LoaderWithSQL, self).get_template(*args, **kwargs)
13-
else:
14-
def load_template(self, *args, **kwargs):
15-
# Force the template loader to run some SQL. Simulates a CMS.
16-
User.objects.all().count()
17-
return super(LoaderWithSQL, self).load_template(*args, **kwargs)
6+
def get_template(self, *args, **kwargs):
7+
# Force the template loader to run some SQL. Simulates a CMS.
8+
User.objects.all().count()
9+
return super(LoaderWithSQL, self).get_template(*args, **kwargs)

tests/middleware.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
def simple_middleware(get_response):
2-
"""
3-
Used to test Django 1.10 compatibility.
4-
"""
52
def middleware(request):
63
return get_response(request)
74
return middleware

tests/panels/test_redirects.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ def test_redirect(self):
2828
redirect['Location'] = 'http://somewhere/else/'
2929
response = self.panel.process_response(self.request, redirect)
3030
self.assertFalse(response is redirect)
31-
try:
32-
self.assertContains(response, '302 Found')
33-
except AssertionError: # Django < 1.9
34-
self.assertContains(response, '302 FOUND')
31+
self.assertContains(response, '302 Found')
3532
self.assertContains(response, 'http://somewhere/else/')
3633

3734
def test_redirect_with_broken_context_processor(self):
@@ -43,20 +40,14 @@ def test_redirect_with_broken_context_processor(self):
4340
redirect['Location'] = 'http://somewhere/else/'
4441
response = self.panel.process_response(self.request, redirect)
4542
self.assertFalse(response is redirect)
46-
try:
47-
self.assertContains(response, '302 Found')
48-
except AssertionError: # Django < 1.9
49-
self.assertContains(response, '302 FOUND')
43+
self.assertContains(response, '302 Found')
5044
self.assertContains(response, 'http://somewhere/else/')
5145

5246
def test_unknown_status_code(self):
5347
redirect = HttpResponse(status=369)
5448
redirect['Location'] = 'http://somewhere/else/'
5549
response = self.panel.process_response(self.request, redirect)
56-
try:
57-
self.assertContains(response, '369 Unknown Status Code')
58-
except AssertionError: # Django < 1.9
59-
self.assertContains(response, '369 UNKNOWN STATUS CODE')
50+
self.assertContains(response, '369 Unknown Status Code')
6051

6152
def test_unknown_status_code_with_reason(self):
6253
redirect = HttpResponse(status=369, reason='Look Ma!')

tests/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
'django.contrib.messages.middleware.MessageMiddleware',
4141
'django.middleware.clickjacking.XFrameOptionsMiddleware',
4242
]
43-
# Django < 1.10
44-
MIDDLEWARE_CLASSES = MIDDLEWARE
4543

4644
ROOT_URLCONF = 'tests.urls'
4745

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def test_check_gzip_middleware_error(self):
387387
def test_middleware_factory_functions_supported(self):
388388
messages = run_checks()
389389

390-
if django.VERSION[:2] < (1, 10) or django.VERSION[:2] >= (2, 0):
390+
if django.VERSION[:2] >= (2, 0):
391391
self.assertEqual(messages, [])
392392
else:
393393
self.assertEqual(messages[0].id, '1_10.W001')

0 commit comments

Comments
 (0)