Skip to content

Commit

Permalink
Merge pull request #5171 from DataShades/ckan-lib-render_snippet-exc
Browse files Browse the repository at this point in the history
Adapt render_snippet exceptions for py3
  • Loading branch information
amercader committed Jan 27, 2020
2 parents bb36a33 + 37e94aa commit 99cadcc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ckan/lib/base.py
Expand Up @@ -88,7 +88,7 @@ def render_snippet(*template_names, **kw):
:type kw: named arguments of any type that are supported by the template
'''

exc = None
last_exc = None
for template_name in template_names:
try:
output = render(template_name, extra_vars=kw)
Expand All @@ -99,12 +99,15 @@ def render_snippet(*template_names, **kw):
return h.literal(output)
except TemplateNotFound as exc:
if exc.name == template_name:
# the specified template doesn't exist - try the next fallback
# the specified template doesn't exist - try the next
# fallback, but store the exception in case it was
# last one
last_exc = exc
continue
# a nested template doesn't exist - don't fallback
raise exc
else:
raise exc or TemplateNotFound
raise last_exc or TemplateNotFound


def render_jinja2(template_name, extra_vars):
Expand Down

0 comments on commit 99cadcc

Please sign in to comment.