Refactor JinjaStaticView to ease customization
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 28 Feb 2017 17:02:55 +0100
changeset 187 480948c69272
parent 186 38a9301ee877
child 188 409f9cbc02c5
Refactor JinjaStaticView to ease customization by extracting out a build_context method. Also add 'base_url' to the default context.
cubicweb_sherpa/views/__init__.py
--- a/cubicweb_sherpa/views/__init__.py	Tue Feb 28 17:02:02 2017 +0100
+++ b/cubicweb_sherpa/views/__init__.py	Tue Feb 28 17:02:55 2017 +0100
@@ -41,9 +41,14 @@
     title = None
 
     def call(self, **kw):
-        self.w(jinja_render(self.template_name,
-                            title=self._cw._(self.title),
-                            data_url=self._cw.datadir_url))
+        self.w(jinja_render(self.template_name, **self.build_context()))
+
+    def build_context(self):
+        return {
+            'title': self._cw._(self.title),
+            'base_url': self._cw.build_url(''),
+            'data_url': self._cw.datadir_url,
+        }
 
 
 def jinja_static_view(template_name, title=None, regid=None, path=None):