template: new "adv_format" filter which use Python's format and return whole value if template is None
This commit is contained in:
parent
08a14fa4ac
commit
8a71ea34b9
1 changed files with 16 additions and 0 deletions
|
|
@ -200,6 +200,7 @@ class Renderer(object):
|
||||||
self.env.filters['cur_gidx'] = self._cur_gidx
|
self.env.filters['cur_gidx'] = self._cur_gidx
|
||||||
self.env.filters['date_days'] = self._date_days
|
self.env.filters['date_days'] = self._date_days
|
||||||
self.env.filters['xmlui_class'] = self._xmlui_class
|
self.env.filters['xmlui_class'] = self._xmlui_class
|
||||||
|
self.env.filters['adv_format'] = self._adv_format
|
||||||
|
|
||||||
def installTranslations(self):
|
def installTranslations(self):
|
||||||
i18n_dir = os.path.join(self.base_dir, 'i18n')
|
i18n_dir = os.path.join(self.base_dir, 'i18n')
|
||||||
|
|
@ -361,6 +362,21 @@ class Renderer(object):
|
||||||
continue
|
continue
|
||||||
return u' '.join(classes) or None
|
return u' '.join(classes) or None
|
||||||
|
|
||||||
|
def _adv_format(self, value, template, **kwargs):
|
||||||
|
"""Advancer formatter
|
||||||
|
|
||||||
|
like format() method, but take care or special values like None
|
||||||
|
@param value(unicode): value to format
|
||||||
|
@param template(None, unicode): template to use with format() method.
|
||||||
|
It will be formatted using value=value and **kwargs
|
||||||
|
None to return value unchanged
|
||||||
|
@return (unicode): formatted value
|
||||||
|
"""
|
||||||
|
if template is None:
|
||||||
|
return value
|
||||||
|
# jinja use string when no special char is used, so we have to convert to unicode
|
||||||
|
return unicode(template).format(value=value, **kwargs)
|
||||||
|
|
||||||
def render(self, template, theme=None, locale=DEFAULT_LOCALE, root_path=u'', css_files=None, css_inline=False, **kwargs):
|
def render(self, template, theme=None, locale=DEFAULT_LOCALE, root_path=u'', css_files=None, css_inline=False, **kwargs):
|
||||||
"""render a template
|
"""render a template
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue