[views/templates] provide a modal main template (closes #3274672)
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 04 Nov 2013 16:06:06 +0100
changeset 9378 4a668dcfa0a0
parent 9377 4e0d8f06efbc
child 9379 b0b1148b6963
[views/templates] provide a modal main template (closes #3274672) The current NonTemplatableViewTemplate may seem to provide the desired feature if a '__notemplate' is provided in the form, unfortunately, it: * wraps the view in a spurious div * calls view.set_stream(), which has the effect of wiping any js/css resource recorded until then by the view, leading to hard-to-track missing resources symptoms
web/views/basetemplates.py
--- a/web/views/basetemplates.py	Wed Jan 08 14:00:31 2014 +0100
+++ b/web/views/basetemplates.py	Mon Nov 04 16:06:06 2013 +0100
@@ -86,6 +86,11 @@
 
 
 @objectify_predicate
+def modal_view(cls, req, rset, *args, **kwargs):
+    if req.form.get('__modal', None):
+        return 1
+
+@objectify_predicate
 def templatable_view(cls, req, rset, *args, **kwargs):
     view = kwargs.pop('view', None)
     if view is None:
@@ -118,6 +123,17 @@
         self._stream = view._stream
 
 
+class ModalMainTemplate(MainTemplate):
+    """ a no-decoration main template for standard views
+    that typically live in a modal context """
+    __regid__ = 'main-template'
+    __select__ = templatable_view() & modal_view()
+
+    def call(self, view):
+        view.set_request_content_type()
+        view.render(w=self.w)
+
+
 class TheMainTemplate(MainTemplate):
     """default main template :