Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/utils.py

Issue 5148261828526080: Issue 2119 - Add get_page_content template function. (Closed)
Patch Set: Use for, break, else control flow for page format guessing. Created April 8, 2015, 8:46 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cms/converters.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/utils.py
diff --git a/cms/utils.py b/cms/utils.py
index 52bcef5008158a00050440cc32df28fc5d7a2981..e654ccbe4ec7e692d17d5509beccd3c29c74cbad 100644
--- a/cms/utils.py
+++ b/cms/utils.py
@@ -17,7 +17,15 @@
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:
+ for format in converters.keys():
Sebastian Noack 2015/04/08 09:09:32 Nit: This creates a new list with all the keys in
kzar 2015/04/08 09:32:11 Done.
+ if source.has_page(page, format):
+ break
+ else:
+ format = "md"
+
params = {
"source": source,
"template": "default",
@@ -46,7 +54,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 +69,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"
+ )()
« no previous file with comments | « cms/converters.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld