PiRSquared17 / app-engine-patch

Automatically exported from code.google.com/p/app-engine-patch
0 stars 0 forks source link

Debug info (paths) for ragendja.template.app_prefixed_loader #224

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What is the expected output? 

Using loader ragendja.template.app_prefixed_loader:
    * X:\project\app\templates\foo\bar.html (File does not exist)

What do you see instead?

Using loader ragendja.template.app_prefixed_loader:

Patch:

diff -r 10b858dbbdb8 web/common/appenginepatch/ragendja/template.py
--- a/web/common/appenginepatch/ragendja/template.py    Mon Sep 21 00:21:18
2009 +0200
+++ b/web/common/appenginepatch/ragendja/template.py    Tue Sep 29 18:40:03
2009 +0200
@@ -37,16 +37,23 @@
         self.tag(getattr(func, "_decorated_function", func).__name__,
compile_func)
         return func

+
+def get_template_sources(template_name, template_dirs=None):
+    """ Returs a collection of paths used to load templates in this module """
+    packed = template_name.split('/', 1)
+    if len(packed) == 2 and packed[0] in app_template_dirs:
+        return [os.path.join(app_template_dirs[packed[0]], packed[1])]
+    return None
+
 # The following defines a template loader that loads templates from a specific
 # app based on the prefix of the template path:
 # get_template("app/template.html") => app/templates/template.html
 # This keeps the code DRY and prevents name clashes.
 def app_prefixed_loader(template_name, template_dirs=None):
-    packed = template_name.split('/', 1)
-    if len(packed) == 2 and packed[0] in app_template_dirs:
-        path = os.path.join(app_template_dirs[packed[0]], packed[1])
+    path = get_template_sources(template_name, template_dirs)
+    if path is not None:
         try:
-            return (open(path).read().decode(settings.FILE_CHARSET), path)
+            return (open(path[0]).read().decode(settings.FILE_CHARSET),
path[0])
         except IOError:
             pass
     raise TemplateDoesNotExist, template_name

Original issue reported on code.google.com by janusz.s...@gmail.com on 29 Sep 2009 at 4:41

GoogleCodeExporter commented 9 years ago
Corection get_template_sources shouldn't return None

diff -r 380273903d97 web/common/appenginepatch/ragendja/template.py
--- a/web/common/appenginepatch/ragendja/template.py    Tue Sep 29 17:01:51 
2009 +0200
+++ b/web/common/appenginepatch/ragendja/template.py    Tue Sep 29 20:55:23 
2009 +0200
@@ -37,16 +37,23 @@
         self.tag(getattr(func, "_decorated_function", func).__name__, compile_func)
         return func

+
+def get_template_sources(template_name, template_dirs=None):
+    """ Returs a collection of paths used to load templates in this module """
+    packed = template_name.split('/', 1)
+    if len(packed) == 2 and packed[0] in app_template_dirs:
+        return [os.path.join(app_template_dirs[packed[0]], packed[1])]
+    return []
+
 # The following defines a template loader that loads templates from a specific
 # app based on the prefix of the template path:
 # get_template("app/template.html") => app/templates/template.html
 # This keeps the code DRY and prevents name clashes.
 def app_prefixed_loader(template_name, template_dirs=None):
-    packed = template_name.split('/', 1)
-    if len(packed) == 2 and packed[0] in app_template_dirs:
-        path = os.path.join(app_template_dirs[packed[0]], packed[1])
+    path = get_template_sources(template_name, template_dirs)
+    if path is not None and len(path) == 1:
         try:
-            return (open(path).read().decode(settings.FILE_CHARSET), path)
+            return (open(path[0]).read().decode(settings.FILE_CHARSET), 
path[0])
         except IOError:
             pass
     raise TemplateDoesNotExist, template_name

Original comment by janusz.s...@gmail.com on 29 Sep 2009 at 6:57