[PATCH 6 of 8 sherpa] Refactor JinjaStaticView to ease customization

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Feb 28 17:08:20 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1488297775 -3600
#      Tue Feb 28 17:02:55 2017 +0100
# Node ID 480948c69272de9cb8097f9a45de461d73751c94
# Parent  38a9301ee8770f5d34790f8bd075921e5b5f5503
Refactor JinjaStaticView to ease customization

by extracting out a build_context method. Also add 'base_url' to the default
context.

diff --git a/cubicweb_sherpa/views/__init__.py b/cubicweb_sherpa/views/__init__.py
--- a/cubicweb_sherpa/views/__init__.py
+++ b/cubicweb_sherpa/views/__init__.py
@@ -39,13 +39,18 @@ class JinjaStaticView(View):
     __abstract__ = True
     template_name = None
     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):
     """Generate a sub-class of :class:`JinjaStaticView` parametrized with its `template_name` and
     `title`.


More information about the saem-devel mailing list