Index: cms/utils.py |
diff --git a/cms/utils.py b/cms/utils.py |
index 52bcef5008158a00050440cc32df28fc5d7a2981..771c91ef5b2196c49142d90b4be76db09921faea 100644 |
--- a/cms/utils.py |
+++ b/cms/utils.py |
@@ -17,7 +17,14 @@ |
from .converters import converters, TemplateConverter |
-def process_page(source, locale, page, format, site_url_override=None): |
+def get_page_params(source, locale, page, format=None, site_url_override=None): |
+ # Guess page format if omitted, but default to Markdown for friendlier exceptions |
+ if format is None: |
+ format = "md" |
+ for fmt in converters.keys(): |
+ if source.has_page(page, fmt): |
+ format = fmt |
Sebastian Noack
2015/04/08 08:38:57
I'd prefer to break when we found a match. Then we
kzar
2015/04/08 08:50:20
Cool, I've never seen an `else` clause for a `for`
|
+ |
params = { |
"source": source, |
"template": "default", |
@@ -46,7 +53,6 @@ def process_page(source, locale, page, format, site_url_override=None): |
# Note: The converter might change some parameters so we can only read in |
# template data here. |
params["templatedata"] = source.read_template(params["template"]) |
- template_converter = TemplateConverter(params, key="templatedata") |
defaultlocale = params["config"].get("general", "defaultlocale") |
params["defaultlocale"] = defaultlocale |
@@ -62,4 +68,10 @@ def process_page(source, locale, page, format, site_url_override=None): |
params["available_locales"] = locales |
params["head"], params["body"] = converter() |
- return template_converter() |
+ return params |
+ |
+def process_page(source, locale, page, format, site_url_override=None): |
+ return TemplateConverter( |
+ get_page_params(source, locale, page, format, site_url_override), |
+ key="templatedata" |
+ )() |