diff --git a/django/core/template/__init__.py b/django/core/template/__init__.py index 713a082735..bc814e0f5f 100644 --- a/django/core/template/__init__.py +++ b/django/core/template/__init__.py @@ -57,7 +57,8 @@ times with multiple contexts) import re from inspect import getargspec from django.utils.functional import curry -from django.conf.settings import DEFAULT_CHARSET, TEMPLATE_DEBUG +from django.conf.settings import DEFAULT_CHARSET +from django.conf import settings __all__ = ('Template','Context','compile_string') @@ -126,7 +127,7 @@ class StringOrigin(Origin): class Template: def __init__(self, template_string, origin=None): "Compilation stage" - if TEMPLATE_DEBUG and origin == None: + if settings.TEMPLATE_DEBUG and origin == None: origin = StringOrigin(template_string) # Could do some crazy stack-frame stuff to record where this string # came from... @@ -401,13 +402,20 @@ class DebugParser(Parser): if not hasattr(e, 'source'): e.source = token.source -if TEMPLATE_DEBUG: - lexer_factory = DebugLexer - parser_factory = DebugParser -else: - lexer_factory = Lexer - parser_factory = Parser +def lexer_factory(*args, **kwargs): + if settings.TEMPLATE_DEBUG: + return DebugLexer(*args, **kwargs) + else: + return Lexer(*args, **kwargs) + +def parser_factory(*args, **kwargs): + if settings.TEMPLATE_DEBUG: + return DebugParser(*args, **kwargs) + else: + return Parser(*args, **kwargs) + + class TokenParser: """ Subclass this and implement the top() method to parse a template line. When diff --git a/django/core/template/loader.py b/django/core/template/loader.py index 106066d26f..d009c3358a 100644 --- a/django/core/template/loader.py +++ b/django/core/template/loader.py @@ -22,7 +22,8 @@ from django.core.exceptions import ImproperlyConfigured from django.core.template import Origin, StringOrigin, Template, Context, TemplateDoesNotExist, add_to_builtins -from django.conf.settings import TEMPLATE_LOADERS, TEMPLATE_DEBUG +from django.conf.settings import TEMPLATE_LOADERS +from django.conf import settings template_source_loaders = [] for path in TEMPLATE_LOADERS: @@ -51,7 +52,7 @@ class LoaderOrigin(Origin): return self.loader(self.loadname, self.dirs)[0] def make_origin(display_name, loader, name, dirs): - if TEMPLATE_DEBUG: + if settings.TEMPLATE_DEBUG: return LoaderOrigin(display_name, loader, name, dirs) else: return None diff --git a/django/core/template/loader_tags.py b/django/core/template/loader_tags.py index 15beec9dff..9c9b991acf 100644 --- a/django/core/template/loader_tags.py +++ b/django/core/template/loader_tags.py @@ -1,7 +1,7 @@ from django.core.template import TemplateSyntaxError, TemplateDoesNotExist, resolve_variable from django.core.template import Library, Context, Node from django.core.template.loader import get_template, get_template_from_string, find_template_source -from django.conf.settings import TEMPLATE_DEBUG + register = Library() class ExtendsError(Exception): @@ -82,6 +82,7 @@ class ConstantIncludeNode(Node): t = get_template(template_path) self.template = t except: + from django.conf.settings import TEMPLATE_DEBUG if TEMPLATE_DEBUG: raise self.template = None diff --git a/django/db/models/fields.py b/django/db/models/fields/__init__.py similarity index 100% rename from django/db/models/fields.py rename to django/db/models/fields/__init__.py diff --git a/django/db/models/manager.py b/django/db/models/manager.py index 79f1560f8b..22715c40c1 100644 --- a/django/db/models/manager.py +++ b/django/db/models/manager.py @@ -9,7 +9,7 @@ from django.db.models.query import handle_legacy_orderlist, orderlist2sql, order GET_ITERATOR_CHUNK_SIZE = 100 class Manager(object): - # Tracks each time a Field instance is created. Used to retain order. + # Tracks each time a Manager instance is created. Used to retain order. creation_counter = 0 def __init__(self): diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py index a95edf6bdc..691b0b63eb 100644 --- a/tests/othertests/templates.py +++ b/tests/othertests/templates.py @@ -1,7 +1,5 @@ from django.conf import settings -# Turn TEMPLATE_DEBUG off, because tests assume that. -settings.TEMPLATE_DEBUG = False from django.core import template from django.core.template import loader @@ -353,6 +351,9 @@ def run_tests(verbosity=0, standalone=False): failed_tests = [] tests = TEMPLATE_TESTS.items() tests.sort() + + # Turn TEMPLATE_DEBUG off, because tests assume that. + old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False for name, vals in tests: install() if 'LANGUAGE_CODE' in vals[1]: @@ -382,6 +383,8 @@ def run_tests(verbosity=0, standalone=False): failed_tests.append(name) loader.template_source_loaders = old_template_loaders deactivate() + settings.TEMPLATE_DEBUG = old_td + if failed_tests and not standalone: msg = "Template tests %s failed." % failed_tests if not verbosity: