Skip to content

Dropped Django 1.7 support #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
Expand Down
53 changes: 0 additions & 53 deletions debug_toolbar/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
87 changes: 29 additions & 58 deletions debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions debug_toolbar/panels/templates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/cache.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}
<h4>{% trans "Summary" %}</h4>
<table>
<thead>
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/headers.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}

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

Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/logging.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}
{% if records %}
<table>
<thead>
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/request.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}

<h4>{% trans "View information" %}</h4>
<table>
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/settings.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}
<table>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/signals.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}
<table>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/sql.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n l10n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
{% load i18n l10n %}{% load static from staticfiles %}
<div class="djdt-clearfix">
<ul class="djdt-stats">
{% for alias, info in databases %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
{% load i18n %}{% load static from staticfiles %}
<div class="djDebugPanelTitle">
<a class="djDebugClose djDebugBack" href=""></a>
<h3>{% trans "SQL explained" %}</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
{% load i18n %}{% load static from staticfiles %}
<div class="djDebugPanelTitle">
<a class="djDebugClose djDebugBack" href=""></a>
<h3>{% trans "SQL profiled" %}</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
{% load i18n %}{% load static from staticfiles %}
<div class="djDebugPanelTitle">
<a class="djDebugClose djDebugBack" href=""></a>
<h3>{% trans "SQL selected" %}</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles%}
{% load i18n %}{% load static from staticfiles%}

<h4>{% blocktrans count staticfiles_dirs|length as dirs_count %}Static file path{% plural %}Static file paths{% endblocktrans %}</h4>
{% if staticfiles_dirs %}
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/timer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}{% load static from staticfiles %}
{% load i18n %}{% load static from staticfiles %}
<h4>{% trans "Resource usage" %}</h4>
<table>
<colgroup>
Expand Down
2 changes: 1 addition & 1 deletion debug_toolbar/templates/debug_toolbar/panels/versions.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load i18n %}{% load cycle from debug_toolbar_compat %}
{% load i18n %}
<table>
<thead>
<tr>
Expand Down
13 changes: 0 additions & 13 deletions debug_toolbar/templatetags/debug_toolbar_compat.py

This file was deleted.

8 changes: 6 additions & 2 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -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
~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion example/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
13 changes: 10 additions & 3 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

DEBUG = True

TEMPLATE_DEBUG = True


# Application definition

Expand All @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions tests/panels/test_redirects.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading