[base views] make it easier to override EntityStartupView behaviour when the rset is empty; closes #2126364 stable
authorFlorent Cayré <florent.cayre@gmail.com>
Wed, 18 Jan 2012 17:27:11 +0100
branchstable
changeset 8174 b3e87e6865ef
parent 8173 5bc91cc51fe3
child 8175 89fcaca0bca0
[base views] make it easier to override EntityStartupView behaviour when the rset is empty; closes #2126364
view.py
--- a/view.py	Wed Jan 18 16:14:34 2012 +0100
+++ b/view.py	Wed Jan 18 17:27:11 2012 +0100
@@ -417,6 +417,10 @@
         """return some rql to be executed if the result set is None"""
         return self.default_rql
 
+    def no_entities(self, **kwargs):
+        """override to display something when no entities were found"""
+        pass
+
     def call(self, **kwargs):
         """override call to execute rql returned by the .startup_rql method if
         necessary
@@ -424,8 +428,11 @@
         rset = self.cw_rset
         if rset is None:
             rset = self.cw_rset = self._cw.execute(self.startup_rql())
-        for i in xrange(len(rset)):
-            self.wview(self.__regid__, rset, row=i, **kwargs)
+        if rset:
+            for i in xrange(len(rset)):
+                self.wview(self.__regid__, rset, row=i, **kwargs)
+        else:
+            self.no_entities(**kwargs)
 
 
 class AnyRsetView(View):