Index: cms/utils.py |
diff --git a/cms/utils.py b/cms/utils.py |
index 66d8498f74582a93b1fff3ccac87879d2877654b..9199e322d9fa942ddeb97e6f93cb018739edeaaa 100644 |
--- a/cms/utils.py |
+++ b/cms/utils.py |
@@ -15,6 +15,8 @@ |
# You should have received a copy of the GNU General Public License |
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+import re |
+ |
from cms.converters import converters, TemplateConverter |
def get_page_params(source, locale, page, format=None, site_url_override=None, |
@@ -35,6 +37,7 @@ def get_page_params(source, locale, page, format=None, site_url_override=None, |
"pagedata": source.read_page(page, format), |
"config": source.read_config(), |
"localized_string_callback": localized_string_callback, |
+ "jinja2_inheritence": False |
} |
localefile = page |
@@ -53,9 +56,12 @@ def get_page_params(source, locale, page, format=None, site_url_override=None, |
except KeyError: |
raise Exception("Page %s uses unknown format %s" % (page, format)) |
- # Note: The converter might change some parameters so we can only read in |
- # template data here. |
- params["templatedata"] = source.read_template(params["template"]) |
+ if format == "tmpl" and re.search(r"{%\s*extends.+?%}", params["pagedata"][0]): |
+ params["jinja2_inheritence"] = True |
+ else: |
+ # Note: The converter might change some parameters so we can only read in |
+ # template data here. |
+ params["templatedata"] = source.read_template(params["template"]) |
defaultlocale = params["config"].get("general", "defaultlocale") |
params["defaultlocale"] = defaultlocale |
@@ -70,7 +76,11 @@ def get_page_params(source, locale, page, format=None, site_url_override=None, |
locales.sort() |
params["available_locales"] = locales |
- params["head"], params["body"] = converter() |
+ if params["jinja2_inheritence"]: |
+ params["body"] = converter() |
+ else: |
+ params["head"], params["body"] = converter() |
+ |
if converter.total_translations > 0: |
params["translation_ratio"] = (1 - |
float(converter.missing_translations) / converter.total_translations) |
@@ -81,8 +91,13 @@ def get_page_params(source, locale, page, format=None, site_url_override=None, |
def process_page(source, locale, page, format=None, site_url_override=None, |
localized_string_callback=None): |
- return TemplateConverter( |
- get_page_params(source, locale, page, format, |
- site_url_override, localized_string_callback), |
- key="templatedata" |
- )() |
+ page_params = get_page_params(source, locale, page, format, |
+ site_url_override, localized_string_callback) |
+ |
+ if page_params["jinja2_inheritence"]: |
+ return page_params["body"] |
+ else: |
+ return TemplateConverter( |
+ page_params, |
+ key="templatedata" |
+ )() |