web/views/basecontrollers.py
changeset 2867 e8581a4f1bae
parent 2792 135580d15d42
parent 2862 08d214ffa514
child 2880 bfc8e1831290
--- a/web/views/basecontrollers.py	Fri Aug 14 15:53:12 2009 +0200
+++ b/web/views/basecontrollers.py	Sun Aug 16 20:27:28 2009 +0200
@@ -298,6 +298,31 @@
             return None
         return None
 
+    def _call_view(self, view, **kwargs):
+        req = self.req
+        divid = req.form.get('divid', 'pageContent')
+        # we need to call pagination before with the stream set
+        stream = view.set_stream()
+        if req.form.get('paginate'):
+            if divid == 'pageContent':
+                # mimick main template behaviour
+                stream.write(u'<div id="pageContent">')
+                vtitle = self.req.form.get('vtitle')
+                if vtitle:
+                    stream.write(u'<h1 class="vtitle">%s</h1>\n' % vtitle)
+            view.pagination(req, self.rset, view.w, not view.need_navigation)
+            if divid == 'pageContent':
+                stream.write(u'<div id="contentmain">')
+        view.render(**kwargs)
+        extresources = req.html_headers.getvalue(skiphead=True)
+        if extresources:
+            stream.write(u'<div class="ajaxHtmlHead">\n') # XXX use a widget ?
+            stream.write(extresources)
+            stream.write(u'</div>\n')
+        if req.form.get('paginate') and divid == 'pageContent':
+            stream.write(u'</div></div>')
+        return stream.getvalue()
+
     @xhtmlize
     def js_view(self):
         # XXX try to use the page-content template
@@ -313,28 +338,7 @@
         except NoSelectableObject:
             vid = req.form.get('fallbackvid', 'noresult')
             view = self.vreg['views'].select(vid, req, rset=rset)
-        divid = req.form.get('divid', 'pageContent')
-        # we need to call pagination before with the stream set
-        stream = view.set_stream()
-        if req.form.get('paginate'):
-            if divid == 'pageContent':
-                # mimick main template behaviour
-                stream.write(u'<div id="pageContent">')
-                vtitle = self.req.form.get('vtitle')
-                if vtitle:
-                    stream.write(u'<h1 class="vtitle">%s</h1>\n' % vtitle)
-            view.pagination(req, rset, view.w, not view.need_navigation)
-            if divid == 'pageContent':
-                stream.write(u'<div id="contentmain">')
-        view.render()
-        extresources = req.html_headers.getvalue(skiphead=True)
-        if extresources:
-            stream.write(u'<div class="ajaxHtmlHead">\n') # XXX use a widget ?
-            stream.write(extresources)
-            stream.write(u'</div>\n')
-        if req.form.get('paginate') and divid == 'pageContent':
-            stream.write(u'</div></div>')
-        return stream.getvalue()
+        return self._call_view(view)
 
     @xhtmlize
     def js_prop_widget(self, propkey, varname, tabindex=None):
@@ -370,7 +374,8 @@
         view = self.vreg['views'].select('inline-creation', self.req,
                                          etype=ttype, peid=peid, rtype=rtype,
                                          role=role)
-        return view.render(etype=ttype, peid=peid, rtype=rtype, role=role)
+        return self._call_view(view, etype=ttype, peid=peid,
+                               rtype=rtype, role=role)
 
     @jsonize
     def js_validate_form(self, action, names, values):