Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a get_template_sources generator function to filesystem and app…

…_directories template loaders, so template-loader debugger can hook into it. Refs #892.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 22746d32a50792247330ea026e0d0ac2a0c2f933 1 parent c616d86
Adrian Holovaty authored November 24, 2005
2  django/core/template/loader.py
@@ -59,7 +59,7 @@ def make_origin(display_name, loader, name, dirs):
59 59
 def find_template_source(name, dirs=None):
60 60
     for loader in template_source_loaders:
61 61
         try:
62  
-            source, display_name  = loader(name, dirs)
  62
+            source, display_name = loader(name, dirs)
63 63
             return (source, make_origin(display_name, loader, name, dirs))
64 64
         except TemplateDoesNotExist:
65 65
             pass
7  django/core/template/loaders/app_directories.py
@@ -27,9 +27,12 @@
27 27
 # It won't change, so convert it to a tuple to save memory.
28 28
 app_template_dirs = tuple(app_template_dirs)
29 29
 
30  
-def load_template_source(template_name, template_dirs=None):
  30
+def get_template_sources(template_name, template_dirs=None):
31 31
     for template_dir in app_template_dirs:
32  
-        filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
  32
+        yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
  33
+
  34
+def load_template_source(template_name, template_dirs=None):
  35
+    for filepath in get_template_sources(template_name, template_dirs):
33 36
         try:
34 37
             return (open(filepath).read(), filepath)
35 38
         except IOError:
9  django/core/template/loaders/filesystem.py
@@ -4,12 +4,15 @@
4 4
 from django.core.template import TemplateDoesNotExist
5 5
 import os
6 6
 
7  
-def load_template_source(template_name, template_dirs=None):
  7
+def get_template_sources(template_name, template_dirs=None):
8 8
     if not template_dirs:
9 9
         template_dirs = TEMPLATE_DIRS
10  
-    tried = []
11 10
     for template_dir in template_dirs:
12  
-        filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
  11
+        yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
  12
+
  13
+def load_template_source(template_name, template_dirs=None):
  14
+    tried = []
  15
+    for filepath in get_template_sources(template_name, template_dirs):
13 16
         try:
14 17
             return (open(filepath).read(), filepath)
15 18
         except IOError:

0 notes on commit 22746d3

Please sign in to comment.
Something went wrong with that request. Please try again.