move view method's logic on the registry, so it's easier to call it from outside an appobject. Also make rset argument optional
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 28 May 2009 18:31:14 +0200
changeset 1985 9c1db4e06095
parent 1984 8d571df6012a
child 1986 96c0e56cb0cf
move view method's logic on the registry, so it's easier to call it from outside an appobject. Also make rset argument optional
appobject.py
cwvreg.py
view.py
--- a/appobject.py	Thu May 28 18:28:29 2009 +0200
+++ b/appobject.py	Thu May 28 18:31:14 2009 +0200
@@ -188,14 +188,8 @@
         return rql
 
     def view(self, __vid, rset=None, __fallback_vid=None, **kwargs):
-        """shortcut to self.vreg.render method avoiding to pass self.req"""
-        try:
-            view = self.vreg.select_view(__vid, self.req, rset, **kwargs)
-        except NoSelectableObject:
-            if __fallback_vid is None:
-                raise
-            view = self.vreg.select_view(__fallback_vid, self.req, rset, **kwargs)
-        return view.render(**kwargs)
+        """shortcut to self.vreg.view method avoiding to pass self.req"""
+        return self.vreg.view(__vid, self.req, rset, __fallback_vid, **kwargs)
 
     def initialize_varmaker(self):
         varmaker = self.req.get_page_data('rql_varmaker')
--- a/cwvreg.py	Thu May 28 18:28:29 2009 +0200
+++ b/cwvreg.py	Thu May 28 18:31:14 2009 +0200
@@ -249,6 +249,16 @@
                 self.exception('error while trying to list possible %s views for %s',
                                vid, rset)
 
+    def view(self, __vid, req, rset=None, __fallback_vid=None, **kwargs):
+        """shortcut to self.vreg.render method avoiding to pass self.req"""
+        try:
+            view = self.select_view(__vid, req, rset, **kwargs)
+        except NoSelectableObject:
+            if __fallback_vid is None:
+                raise
+            view = self.select_view(__fallback_vid, req, rset, **kwargs)
+        return view.render(**kwargs)
+
     def select_box(self, oid, *args, **kwargs):
         """return the most specific view according to the result set"""
         try:
@@ -270,12 +280,11 @@
         except (NoSelectableObject, ObjectNotFound):
             return
 
-    def select_view(self, __vid, req, rset, **kwargs):
+    def select_view(self, __vid, req, rset=None, **kwargs):
         """return the most specific view according to the result set"""
         views = self.registry_objects('views', __vid)
         return self.select(views, req, rset, **kwargs)
 
-
     # properties handling #####################################################
 
     def user_property_keys(self, withsitewide=False):
--- a/view.py	Thu May 28 18:28:29 2009 +0200
+++ b/view.py	Thu May 28 18:31:14 2009 +0200
@@ -207,7 +207,7 @@
 
     # view utilities ##########################################################
 
-    def wview(self, __vid, rset, __fallback_vid=None, **kwargs):
+    def wview(self, __vid, rset=None, __fallback_vid=None, **kwargs):
         """shortcut to self.view method automatically passing self.w as argument
         """
         self.view(__vid, rset, __fallback_vid, w=self.w, **kwargs)