comparison src/tools/common/template.py @ 2394:7bfcc431f66d

template: added media_path to template data
author Goffi <goffi@goffi.org>
date Fri, 27 Oct 2017 08:36:24 +0200
parents 07e1543d6992
children 221478058d8a
comparison
equal deleted inserted replaced
2393:8ed4ac10cb5e 2394:7bfcc431f66d
375 if template is None: 375 if template is None:
376 return value 376 return value
377 # jinja use string when no special char is used, so we have to convert to unicode 377 # jinja use string when no special char is used, so we have to convert to unicode
378 return unicode(template).format(value=value, **kwargs) 378 return unicode(template).format(value=value, **kwargs)
379 379
380 def render(self, template, theme=None, locale=DEFAULT_LOCALE, root_path=u'', css_files=None, css_inline=False, **kwargs): 380 def render(self, template, theme=None, locale=DEFAULT_LOCALE, root_path=u'', media_path=u'', css_files=None, css_inline=False, **kwargs):
381 """render a template 381 """render a template
382 382
383 @param template(unicode): template to render (e.g. blog/articles.html) 383 @param template(unicode): template to render (e.g. blog/articles.html)
384 @param theme(unicode): template theme 384 @param theme(unicode): template theme
385 @param root_path(unicode): prefix of the path/URL to use for template root 385 @param root_path(unicode): prefix of the path/URL to use for template root
386 must end with a u'/'
387 @param media_path(unicode): prefix of the SàT media path/URL to use for template root
386 must end with a u'/' 388 must end with a u'/'
387 @param css_files(list[unicode],None): CSS files to used 389 @param css_files(list[unicode],None): CSS files to used
388 CSS files must be in static dir of the template 390 CSS files must be in static dir of the template
389 use None for automatic selection of CSS files based on template category 391 use None for automatic selection of CSS files based on template category
390 None is recommended. General static/style.css and theme file name will be used. 392 None is recommended. General static/style.css and theme file name will be used.
422 424
423 scripts_handler = ScriptsHandler(self, template_path, template_root_dir, root_path) 425 scripts_handler = ScriptsHandler(self, template_path, template_root_dir, root_path)
424 self.setLocale(locale) 426 self.setLocale(locale)
425 # XXX: theme used in template arguments is the requested theme, which may differ from actual theme 427 # XXX: theme used in template arguments is the requested theme, which may differ from actual theme
426 # if the template doesn't exist in the requested theme. 428 # if the template doesn't exist in the requested theme.
427 return template_source.render(theme=theme, root_path=root_path, css_files=css_files, locale=self._locale, gidx=Indexer(), script=scripts_handler, **kwargs) 429 return template_source.render(theme=theme, root_path=root_path, media_path=media_path, css_files=css_files, locale=self._locale, gidx=Indexer(), script=scripts_handler, **kwargs)