Mercurial > hg > decoupage
changeset 101:747c7e337c56
add local directory for template rendering
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 31 Jan 2017 10:24:42 -0800 |
parents | 82ee67b95a0c |
children | 2b38f9a43f84 |
files | decoupage/web.py setup.py |
diffstat | 2 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/decoupage/web.py Tue Aug 23 19:30:03 2016 -0700 +++ b/decoupage/web.py Tue Jan 31 10:24:42 2017 -0800 @@ -24,6 +24,7 @@ from genshi.template import TemplateLoader from genshi.template.base import TemplateError from genshi.template.base import TemplateSyntaxError +from genshi.template.loader import TemplateNotFound from martini.config import ConfigMunger from paste.fileapp import FileApp from pkg_resources import iter_entry_points @@ -31,9 +32,11 @@ from pkg_resources import resource_filename from webob import Request, Response, exc + transformers = transformers() string = (str, unicode) + class FileSorter(object): def __init__(self, *keys): self.keys = keys @@ -237,15 +240,20 @@ if template in os.listdir(_directory): break else: - raise IOError("template %s not found" % template) + raise TemplateNotFound("template %s not found" % template) + + # extend template `search_path` to include local directory + self.loader.search_path.insert(0, directory) try: template = self.loader.load(template) res = template.generate(**data).render('html', doctype='html') - except (TemplateError, TemplateSyntaxError), e: + except (TemplateError, TemplateSyntaxError, TemplateNotFound), e: if local_index: print repr(e) return self.fileserver(local_index) raise + finally: + self.loader.search_path.pop(0) # set charset if given kw = {}