diff roundup/cgi/engine_jinja2.py @ 6054:ffaf89a4a9d9

use jinja2 i18n extension enable autoescape for jinja2 templates
author Christof Meerwald <cmeerw@cmeerw.org>
date Mon, 13 Jan 2020 21:18:42 +0000
parents 238dafbe521c
children ec1f725f5c91
line wrap: on
line diff
--- a/roundup/cgi/engine_jinja2.py	Mon Jan 13 09:36:40 2020 +0100
+++ b/roundup/cgi/engine_jinja2.py	Mon Jan 13 21:18:42 2020 +0000
@@ -47,7 +47,8 @@
     def __init__(self, dir):
         self._env = jinja2.Environment(
             loader=jinja2.FileSystemLoader(dir),
-            extensions=[]
+            extensions=['jinja2.ext.i18n'],
+            autoescape=True
         )
 
         # Adding a custom filter that can transform roundup's vars to unicode
@@ -87,7 +88,10 @@
     def render(self, client, classname, request, **options):
         # [ ] limit the information passed to the minimal necessary set
         c = context(client, self, classname, request)
-        c.update({'options': options})
+
+        c.update({'options': options,
+                  'gettext': lambda s: s2u(client.gettext(s)),
+                  'ngettext': lambda s, p, n: s2u(client.ngettext(s, p, n))})
         s = self._tpl.render(c)
         return s if sys.version_info[0] > 2 else \
             s.encode(client.STORAGE_CHARSET, )

Roundup Issue Tracker: http://roundup-tracker.org/