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

Unified Diff: cms/converters.py

Issue 29469568: Issue 5331 - Adds has_string() global (Closed)
Patch Set: Created June 20, 2017, 2:51 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
« no previous file with comments | « no previous file | tests/expected_output/global » ('j') | tests/test_site/pages/global.tmpl » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/converters.py
===================================================================
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -376,16 +376,17 @@
filters = {
'translate': self.translate,
'linkify': self.linkify,
'toclist': self.toclist,
}
globals = {
'get_string': self.get_string,
+ 'has_string': self.has_string,
'get_page_content': self.get_page_content,
}
for dirname, dictionary in [('filters', filters),
('globals', globals)]:
for filename in self._params['source'].list_files(dirname):
root, ext = os.path.splitext(filename)
if ext.lower() != '.py':
@@ -437,16 +438,26 @@
localedata = self._params['source'].read_locale(self._params['locale'],
page)
default = localedata[name]
Vasily Kuznetsov 2017/06/20 17:38:27 I didn't pay attention to this line when looking i
return jinja2.Markup(self.localize_string(
page, name, default, '', localedata, html_escapes
))
+ def has_string(self, name, page=None):
+ if page is None:
+ page = self._params['page']
+
+ localedata = self._params['source'].read_locale(self._params['locale'],
Vasily Kuznetsov 2017/06/20 17:38:27 Maybe create a small protected method for this log
Jon Sonesen 2017/06/21 07:53:54 yeah, this is good. but what about the if page is
Vasily Kuznetsov 2017/06/21 08:17:00 Yeah, all true. I was thinking to leave that part
+ page)
+ if name in localedata:
Vasily Kuznetsov 2017/06/20 17:38:28 `return name in localedata` would do the same in o
Jon Sonesen 2017/06/21 07:53:54 Acknowledged.
+ return True
+ return False
+
def get_page_content(self, page, locale=None):
from cms.utils import get_page_params
if locale is None:
locale = self._params['locale']
return get_page_params(self._params['source'], locale, page)
def linkify(self, page, locale=None, **attrs):
« no previous file with comments | « no previous file | tests/expected_output/global » ('j') | tests/test_site/pages/global.tmpl » ('J')

Powered by Google App Engine
This is Rietveld