Skip to content

Commit

Permalink
[#5131] index template with template path instead of numeric index
Browse files Browse the repository at this point in the history
  • Loading branch information
HoussamBedja committed Jan 23, 2020
1 parent 6257297 commit d9267ec
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ckan/lib/jinja_extensions.py
Expand Up @@ -106,13 +106,13 @@ def parse(self, parser):
node = nodes.Extends(lineno)
template_path = parser.filename
# find where in the search path this template is from
index = 0
current_path = None
if not hasattr(self, 'searchpath'):
return node
for searchpath in self.searchpath:
if template_path.startswith(searchpath):
current_path = searchpath
break
index += 1

# get filename from full path
filename = template_path[len(searchpath) + 1:]
Expand All @@ -128,8 +128,8 @@ def parse(self, parser):
% template_path)

# provide our magic format
# format is *<search path parent index>*<template name>
magic_filename = '*' + str(index) + '*' + filename
# format is *<search path parent directory>*<template name>
magic_filename = '*' + current_path + '*' + filename
# set template
node.template = nodes.Const(magic_filename)
return node
Expand Down Expand Up @@ -183,13 +183,14 @@ class CkanFileSystemLoader(loaders.FileSystemLoader):
def get_source(self, environment, template):
# if the template name starts with * then this should be
# treated specially.
# format is *<search path parent index>*<template name>
# format is *<search path parent directory>*<template name>
# so we only search from then downwards. This allows recursive
# ckan_extends tags
if template.startswith('*'):
parts = template.split('*')
template = parts[2]
searchpaths = self.searchpath[int(parts[1]) + 1:]
index = self.searchpath.index(parts[1])
searchpaths = self.searchpath[index + 1:]
else:
searchpaths = self.searchpath
# end of ckan changes
Expand Down

0 comments on commit d9267ec

Please sign in to comment.