Ticket #1321: modularised_templates.diff
File modularised_templates.diff, 11.3 KB (added by , 19 years ago) |
---|
-
django/utils/datastructures.py
224 224 current[bits[-1]] = v 225 225 except TypeError: # Special-case if current isn't a dict. 226 226 current = {bits[-1] : v} 227 228 class LazySettings: 229 """ 230 A lazy proxy for either global django settings or a custom settings object. 231 """ 232 def __init__(self): 233 self.__dict__['_target'] = None 234 235 def __getattr__(self, name): 236 if self._target is None: 237 self.import_settings() 238 return getattr(self._target, name) 239 240 def __setattr__(self, name, value): 241 if name == '_target': 242 self.__dict__[name] = value 243 else: 244 setattr(self._target, name, value) 245 246 def import_settings(self): 247 from django.conf import settings 248 self.__dict__['_target'] = settings -
django/template/defaultfilters.py
1 1 "Default variable filters" 2 2 3 from django.template import resolve_variable, Library 4 from django.conf import settings 3 from django.template import resolve_variable, Library, settings 5 4 from django.utils.translation import gettext 6 5 import re 7 6 import random as random_module … … 327 326 # DATES # 328 327 ################### 329 328 330 def date(value, arg= settings.DATE_FORMAT):329 def date(value, arg=None): 331 330 "Formats a date according to the given format" 332 331 from django.utils.dateformat import format 332 if arg is None: 333 arg = settings.DATE_FORMAT 333 334 return format(value, arg) 334 335 335 def time(value, arg= settings.TIME_FORMAT):336 def time(value, arg=None): 336 337 "Formats a time according to the given format" 337 338 from django.utils.dateformat import time_format 339 if arg is None: 340 arg = settings.TIME_FORMAT 338 341 return time_format(value, arg) 339 342 340 343 def timesince(value): -
django/template/__init__.py
57 57 import re 58 58 from inspect import getargspec 59 59 from django.utils.functional import curry 60 from django.conf import settings 60 from django.utils.datastructures import LazySettings 61 settings = LazySettings() 61 62 from django.template.context import Context, RequestContext, ContextPopException 62 63 63 64 __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') … … 90 91 # global list of libraries to load by default for a new parser 91 92 builtins = [] 92 93 94 ################# 95 # CONFIGURATION # 96 ################# 97 class TemplateSettings: 98 # TODO - eliminate duplication of global_settings? 99 TEMPLATE_DIRS = () 100 DEFAULT_CHARSET = "utf-8" 101 DEBUG = False 102 DATE_FORMAT = 'N j, Y' 103 DATETIME_FORMAT = 'N j, Y, P' 104 TEMPLATE_LOADERS = ( 105 'django.template.loaders.filesystem.load_template_source', 106 'django.template.loaders.app_directories.load_template_source', 107 # 'django.template.loaders.eggs.load_template_source', 108 ) 109 TEMPLATE_FILE_EXTENSION = '.html' 110 TEMPLATE_DEBUG = False 111 TEMPLATE_STRING_IF_INVALID = '' 112 113 def configure(**options): 114 """Set configuration options for the template package.""" 115 global settings 116 new_settings = TemplateSettings() 117 for k, v in options.items(): 118 if not hasattr(new_settings, k): 119 raise Exception('"%s" is not a valid template config setting' % k) 120 setattr(new_settings, k, v) 121 settings._target = new_settings 122 123 ####################### 124 # TEMPLATE EXCEPTIONS # 125 ####################### 93 126 class TemplateSyntaxError(Exception): 94 127 pass 95 128 -
django/template/loaders/app_directories.py
1 1 # Wrapper for loading templates from "template" directories in installed app packages. 2 2 3 from django.conf import settings4 3 from django.core.exceptions import ImproperlyConfigured 5 from django.template import TemplateDoesNotExist 4 from django.template import TemplateDoesNotExist, settings 6 5 import os 7 6 8 # At compile time, cache the directories to search. 9 app_template_dirs = [] 10 for app in settings.INSTALLED_APPS: 11 i = app.rfind('.') 12 if i == -1: 13 m, a = app, None 14 else: 15 m, a = app[:i], app[i+1:] 16 try: 17 if a is None: 18 mod = __import__(m, '', '', []) 19 else: 20 mod = getattr(__import__(m, '', '', [a]), a) 21 except ImportError, e: 22 raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0]) 23 template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') 24 if os.path.isdir(template_dir): 25 app_template_dirs.append(template_dir) 7 app_template_dirs = None 26 8 27 # It won't change, so convert it to a tuple to save memory. 28 app_template_dirs = tuple(app_template_dirs) 9 def _ensure_setup(): 10 # cache the directories to search. 11 global app_template_dirs 12 if app_template_dirs is None: 13 app_template_dirs = [] 14 for app in settings.INSTALLED_APPS: 15 i = app.rfind('.') 16 if i == -1: 17 m, a = app, None 18 else: 19 m, a = app[:i], app[i+1:] 20 try: 21 if a is None: 22 mod = __import__(m, '', '', []) 23 else: 24 mod = getattr(__import__(m, '', '', [a]), a) 25 except ImportError, e: 26 raise ImproperlyConfigured, 'ImportError %s: %s' % (app, e.args[0]) 27 template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') 28 if os.path.isdir(template_dir): 29 app_template_dirs.append(template_dir) 30 31 # It won't change, so convert it to a tuple to save memory. 32 app_template_dirs = tuple(app_template_dirs) 29 33 30 34 def get_template_sources(template_name, template_dirs=None): 35 _ensure_setup() 31 36 for template_dir in app_template_dirs: 32 37 yield os.path.join(template_dir, template_name) + settings.TEMPLATE_FILE_EXTENSION 33 38 -
django/template/loaders/filesystem.py
1 1 # Wrapper for loading templates from the filesystem. 2 2 3 from django.conf import settings 4 from django.template import TemplateDoesNotExist 3 from django.template import TemplateDoesNotExist, settings 5 4 import os 6 5 7 6 def get_template_sources(template_name, template_dirs=None): -
django/template/defaulttags.py
2 2 3 3 from django.template import Node, NodeList, Template, Context, resolve_variable 4 4 from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END 5 from django.template import get_library, Library, InvalidTemplateLibrary 6 from django.conf import settings 5 from django.template import get_library, Library, InvalidTemplateLibrary, settings 7 6 import sys 8 7 9 8 register = Library() -
django/template/context.py
1 from django. confimport settings1 from django.template import settings 2 2 from django.core.exceptions import ImproperlyConfigured 3 3 4 4 _standard_context_processors = None -
django/template/loader_tags.py
1 1 from django.template import TemplateSyntaxError, TemplateDoesNotExist, resolve_variable 2 2 from django.template import Library, Context, Node 3 3 from django.template.loader import get_template, get_template_from_string, find_template_source 4 from django. confimport settings4 from django.template import settings 5 5 6 6 register = Library() 7 7 -
django/template/loader.py
22 22 23 23 from django.core.exceptions import ImproperlyConfigured 24 24 from django.template import Origin, StringOrigin, Template, Context, TemplateDoesNotExist, add_to_builtins 25 from django. confimport settings25 from django.template import settings 26 26 27 27 template_source_loaders = None 28 28 -
tests/standalone_tests.py
1 #!/usr/bin/env python 2 3 # Runs the test scripts in the 'standalone' dir 4 import os 5 STANDALONE_TESTS_DIR = "standalone" 6 7 standalone_tests_dir = os.path.join(os.path.dirname(__file__), STANDALONE_TESTS_DIR) 8 for f in os.listdir(standalone_tests_dir): 9 if f.endswith('.py') and not f.startswith('__init__'): 10 # run script 11 # TODO - What's the correct cross platform way to do this? 12 print "Running test script %s:" % f 13 print "---------------------" + "-" * len(f) 14 os.system('"%s"' % os.path.join(standalone_tests_dir, f)) -
tests/standalone/components.py
Property changes on: tests/standalone_tests.py ___________________________________________________________________ Name: svn:executable + *
1 #!/usr/bin/env python 2 3 # Tests to ensure that Django components are usable without 4 # a DJANGO_SETTINGS_MODULE. This must be executed as a standalone 5 # script to make sure django.settings hasn't already been imported 6 7 import os 8 try: 9 del os.environ['DJANGO_SETTINGS_MODULE'] 10 except KeyError: 11 pass 12 13 import unittest 14 15 class TestTemplate(unittest.TestCase): 16 17 def test_import(self): 18 # make sure we can import django.template without exceptions 19 from django import template 20 21 def test_loader(self): 22 from django import template 23 from django.template import loader 24 25 template.configure(TEMPLATE_DIRS=(os.path.dirname(__file__),)) 26 s = loader.render_to_string('template_test') 27 self.assertEqual(s, 'Hello world') 28 29 if __name__ == '__main__': 30 unittest.main() 31 -
tests/standalone/template_test.html
Property changes on: tests/standalone/components.py ___________________________________________________________________ Name: svn:executable + *
1 Hello world 2 No newline at end of file