Moved fields.py. Fixed template debug unit test failures.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1699 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams 2005-12-16 15:51:08 +00:00
parent ecebbb200f
commit c86bfac264
6 changed files with 27 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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: