Skip to content
This repository
Browse code

Refactor of template loaders

renamed layoutloader to pagelayout
added template model template loader
  • Loading branch information...
commit c37f4811b534aadedda632924f25e2be3b41c47a 1 parent 0a4cdd7
Stephan Adig authored March 21, 2012
7  cocoyam/layouts/templateloader/layoutloader.py → cocoyam/layouts/templateloader/pagelayout.py
@@ -15,7 +15,8 @@ def load_template_source(self, template_name, template_dirs=None):
15 15
         """
16 16
         if template_name is not None and template_name != "":
17 17
             try:
18  
-                template=PageLayout.objects.get(slug=template_name)
  18
+                # check first for the page 
  19
+                template=PageLayout.objects.get(idname=template_name)
19 20
                 contents=template.layout
20 21
                 if template.parent_layout is not None:
21 22
                     contents="{%"
@@ -23,7 +24,7 @@ def load_template_source(self, template_name, template_dirs=None):
23 24
                     contents+= "%}"
24 25
                     contents+="%s" % template.layout
25 26
                 return (contents.decode(settings.FILE_CHARSET),"hello")
26  
-            except Exception,e:
27  
-                pass
  27
+            except PageLayout.DoesNotExist:
  28
+                #
28 29
         raise TemplateDoesNotExist(template_name)
29 30
 
24  cocoyam/layouts/templateloader/template.py
... ...
@@ -0,0 +1,24 @@
  1
+from django.template.base import TemplateDoesNotExist
  2
+from django.template.loader import BaseLoader
  3
+from django.conf import settings
  4
+
  5
+from cocoyam.layouts.models import Templates
  6
+
  7
+class Loader(BaseLoader):
  8
+    is_usable = True
  9
+
  10
+    def load_template_source(self, template_name, template_dirs=None):
  11
+        """
  12
+        Loads templates from Python eggs via pkg_resource.resource_string.
  13
+
  14
+        For every installed app, it tries to get the resource (app, template_name).
  15
+        """
  16
+        if template_name is not None and template_name != "":
  17
+            try:
  18
+                template=Templates.objects.get(idname=template_name)
  19
+                contents=template.template
  20
+                return (contents.decode(settings.FILE_CHARSET),"hello")
  21
+            except Templates.DoesNotExist,e:
  22
+                pass
  23
+        raise TemplateDoesNotExist(template_name)
  24
+

0 notes on commit c37f481

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