Ticket #500: optional_template_file_extensions.2.diff
File optional_template_file_extensions.2.diff, 5.3 KB (added by , 19 years ago) |
---|
-
django/conf/global_settings.py
91 91 # List of locations of the template source files, in search order. 92 92 TEMPLATE_DIRS = () 93 93 94 # Extension on all templates.94 # Default extension for templates if none is given. 95 95 TEMPLATE_FILE_EXTENSION = '.html' 96 96 97 # Default extension for admin templates. 98 ADMIN_TEMPLATE_FILE_EXTENSION = '.html' 99 97 100 # List of callables that know how to import templates from various sources. 98 101 # See the comments in django/core/template/loader.py for interface 99 102 # documentation. -
django/core/template/loaders/app_directories.py
1 1 # Wrapper for loading templates from "template" directories in installed app packages. 2 2 3 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 3 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION, ADMIN_TEMPLATE_FILE_EXTENSION 4 4 from django.core.exceptions import ImproperlyConfigured 5 5 from django.core.template import TemplateDoesNotExist 6 6 import os … … 28 28 app_template_dirs = tuple(app_template_dirs) 29 29 30 30 def get_template_sources(template_name, template_dirs=None): 31 admin_template_name = None 32 if not os.path.splitext(template_name): 33 # Only append file extension if there isn't an extension already. 34 if TEMPLATE_FILE_EXTENSION != ADMIN_TEMPLATE_FILE_EXTENSION: 35 admin_template_name = template_name + TEMPLATE_FILE_EXTENSION 36 template_name = template_name + TEMPLATE_FILE_EXTENSION 31 37 for template_dir in app_template_dirs: 32 yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION 38 yield os.path.join(template_dir, template_name) 39 if admin_template_name: 40 yield os.path.join(template_dir, admin_template_name) 33 41 34 42 def load_template_source(template_name, template_dirs=None): 35 43 for filepath in get_template_sources(template_name, template_dirs): -
django/core/template/loaders/eggs.py
6 6 resource_string = None 7 7 8 8 from django.core.template import TemplateDoesNotExist 9 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 9 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION, ADMIN_TEMPLATE_FILE_EXTENSION 10 import os 10 11 11 12 def load_template_source(template_name, template_dirs=None): 12 13 """ … … 15 16 For every installed app, it tries to get the resource (app, template_name). 16 17 """ 17 18 if resource_string is not None: 18 pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION 19 admin_pkg_name = None 20 if not os.path.splitext(template_name): 21 # Only append TEMPLATE_FILE_EXTENSION if there isn't an extension already. 22 if TEMPLATE_FILE_EXTENSION != ADMIN_TEMPLATE_FILE_EXTENSION: 23 admin_pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION 24 template_name = template_name + TEMPLATE_FILE_EXTENSION 25 pkg_name = 'templates/' + template_name 19 26 for app in INSTALLED_APPS: 20 27 try: 21 28 return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name)) 22 29 except: 23 30 pass 31 if admin_pkg_name: 32 try: 33 return (resource_string(app, admin_pkg_name), 'egg:%s:%s ' % (app, admin_pkg_name)) 24 34 raise TemplateDoesNotExist, template_name 25 35 load_template_source.is_usable = resource_string is not None -
django/core/template/loaders/filesystem.py
1 1 # Wrapper for loading templates from the filesystem. 2 2 3 from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSION 3 from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSION, ADMIN_TEMPLATE_FILE_EXTENSION 4 4 from django.core.template import TemplateDoesNotExist 5 5 import os 6 6 7 7 def get_template_sources(template_name, template_dirs=None): 8 8 if not template_dirs: 9 9 template_dirs = TEMPLATE_DIRS 10 if not os.path.splitext(template_name): 11 # Only append TEMPLATE_FILE_EXTENSION if there isn't an extension already. 12 if TEMPLATE_FILE_EXTENSION != ADMIN_TEMPLATE_FILE_EXTENSION: 13 admin_template_name = template_name + TEMPLATE_FILE_EXTENSION 14 template_name = template_name + TEMPLATE_FILE_EXTENSION 10 15 for template_dir in template_dirs: 11 yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION 16 yield os.path.join(template_dir, template_name) 17 if admin_template_name: 18 yield os.path.join(template_dir, admin_template_name) 12 19 13 20 def load_template_source(template_name, template_dirs=None): 14 21 tried = []