Permalink
Browse files

Refactor of template loaders

renamed layoutloader to pagelayout
added template model template loader
  • Loading branch information...
1 parent 0a4cdd7 commit c37f4811b534aadedda632924f25e2be3b41c47a @sadig committed Mar 21, 2012
View
7 ...am/layouts/templateloader/layoutloader.py → cocoyam/layouts/templateloader/pagelayout.py
@@ -15,15 +15,16 @@ def load_template_source(self, template_name, template_dirs=None):
"""
if template_name is not None and template_name != "":
try:
- template=PageLayout.objects.get(slug=template_name)
+ # check first for the page
+ template=PageLayout.objects.get(idname=template_name)
contents=template.layout
if template.parent_layout is not None:
contents="{%"
contents+=' extends "%s" ' % template.parent_layout.slug
contents+= "%}"
contents+="%s" % template.layout
return (contents.decode(settings.FILE_CHARSET),"hello")
- except Exception,e:
- pass
+ except PageLayout.DoesNotExist:
+ #
raise TemplateDoesNotExist(template_name)
View
24 cocoyam/layouts/templateloader/template.py
@@ -0,0 +1,24 @@
+from django.template.base import TemplateDoesNotExist
+from django.template.loader import BaseLoader
+from django.conf import settings
+
+from cocoyam.layouts.models import Templates
+
+class Loader(BaseLoader):
+ is_usable = True
+
+ def load_template_source(self, template_name, template_dirs=None):
+ """
+ Loads templates from Python eggs via pkg_resource.resource_string.
+
+ For every installed app, it tries to get the resource (app, template_name).
+ """
+ if template_name is not None and template_name != "":
+ try:
+ template=Templates.objects.get(idname=template_name)
+ contents=template.template
+ return (contents.decode(settings.FILE_CHARSET),"hello")
+ except Templates.DoesNotExist,e:
+ pass
+ raise TemplateDoesNotExist(template_name)
+

0 comments on commit c37f481

Please sign in to comment.