Skip to content

Commit 5cd851c

Browse files
committed
Check template debug settings in a transition-sensitive way.
1 parent b692efd commit 5cd851c

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Changes
5454
~~~~~~~
5555

5656

57+
Unreleased
58+
----------
59+
60+
The template debug settings are checked properly for people still using
61+
``TEMPLATE_DEBUG`` in newer versions of Django.
62+
63+
5764
v1.2 --- 2016-01-16
5865
-------------------
5966

django_coverage_plugin/plugin.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,38 @@ class DjangoTemplatePluginException(Exception):
3535
SHOW_TRACING = False
3636

3737

38-
if django.VERSION >= (1, 8):
39-
def check_debug():
40-
from django.conf import settings
41-
templates = settings.TEMPLATES
38+
def check_debug():
39+
"""Check that Django's template debugging is enabled.
40+
41+
Django's built-in "template debugging" records information the plugin needs
42+
to do its work. Check that the setting is correct, and raise an exception
43+
if it is not.
44+
45+
"""
46+
# The settings for templates changed in Django 1.8 from TEMPLATE_DEBUG to
47+
# TEMPLATES[..]['debug']. Django 1.9 tolerated both forms, 1.10 insists on
48+
# the new form. Don't try to be version-specific here. If the new
49+
# settings exist, use them, otherwise use the old.
50+
51+
from django.conf import settings
52+
templates = getattr(settings, 'TEMPLATES', [])
53+
if templates:
54+
# New-style settings.
4255
if len(templates) > 1:
4356
raise DjangoTemplatePluginException("Can't use multiple template engines.")
4457
template_settings = templates[0]
4558
if template_settings['BACKEND'] != 'django.template.backends.django.DjangoTemplates':
4659
raise DjangoTemplatePluginException("Can't use non-Django templates.")
4760
if not template_settings.get('OPTIONS', {}).get('debug', False):
4861
raise DjangoTemplatePluginException("Template debugging must be enabled in settings.")
49-
else:
50-
def check_debug():
51-
from django.conf import settings
62+
else:
63+
# Old-style settings.
5264
if not settings.TEMPLATE_DEBUG:
5365
raise DjangoTemplatePluginException(
5466
"Template debugging must be enabled in settings."
5567
)
5668

69+
5770
if django.VERSION >= (1, 9):
5871
# Since we are grabbing at internal details, we have to adapt as they
5972
# change over versions.

0 commit comments

Comments
 (0)