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

Unified Diff: cms/utils.py

Issue 5694103719247872: Issue 2133 - Allow to specify default translation inline in pages rather than in a separate file (Closed)
Patch Set: Created March 12, 2015, 7:34 p.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
« cms/sources.py ('K') | « cms/sources.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
===================================================================
--- a/cms/utils.py
+++ b/cms/utils.py
@@ -17,17 +17,16 @@
from .converters import converters, TemplateConverter
def process_page(source, locale, page, format, site_url_override=None):
params = {
"source": source,
"template": "default",
"locale": locale,
- "title": "title",
"page": page,
"pagedata": source.read_page(page, format),
"config": source.read_config(),
}
localefile = page
if params["config"].has_option("locale_overrides", page):
localefile = params["config"].get("locale_overrides", page)
@@ -44,17 +43,21 @@ def process_page(source, locale, page, f
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"])
template_converter = TemplateConverter(params, key="templatedata")
- params["available_locales"] = sorted(
- filter(
- lambda locale: source.has_locale(locale, localefile),
- source.list_locales()
- )
- )
+ params["defaultlocale"] = params["config"].get("general", "defaultlocale")
+
+ params["available_locales"] = [
+ locale
+ for locale in source.list_locales()
+ if source.has_locale(locale, localefile)
+ ]
+ if params["defaultlocale"] not in params["available_locales"]:
+ params["available_locales"].append(params["defaultlocale"])
+ params["available_locales"].sort()
Sebastian Noack 2015/03/12 20:33:46 Four inline lookups for "available_locales" and th
Wladimir Palant 2015/03/12 20:57:02 Not sure it really makes the code better here but
Sebastian Noack 2015/03/12 21:08:19 Much better. Thanks.
params["head"], params["body"] = converter()
return template_converter()
« cms/sources.py ('K') | « cms/sources.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld