[entities] fix previous_entity and next_entity methods since entry_of is an optional relation
authorSandrine Ribeau <sandrine.ribeau@logilab.fr>
Wed, 04 Nov 2009 17:01:42 -0800
changeset 141 6102b385b8a3
parent 140 c12f85ec602f
child 142 d06dd0be09ce
[entities] fix previous_entity and next_entity methods since entry_of is an optional relation
entities.py
--- a/entities.py	Wed Nov 04 12:40:43 2009 -0800
+++ b/entities.py	Wed Nov 04 17:01:42 2009 -0800
@@ -100,18 +100,29 @@
     # IPrevNext interface #####################################################
 
     def next_entity(self):
-        rql = ('Any B ORDERBY B ASC LIMIT 1 '
-               'WHERE B is BlogEntry, B entry_of BL, BL eid %(blog)s, '
-               'B eid > %(eid)s')
-        rset = self.req.execute(rql, {'blog': self.entry_of[0].eid, 'eid': self.eid})
+        if self.entry_of:
+            rql = ('Any B ORDERBY B ASC LIMIT 1 '
+                   'WHERE B is BlogEntry, B entry_of BL, BL eid %(blog)s, '
+                   'B eid > %(eid)s')
+            rset = self.req.execute(rql, {'blog': self.entry_of[0].eid, 'eid': self.eid})
+        else:
+            rql = ('Any B ORDERBY B ASC LIMIT 1 '
+                   'WHERE B is BlogEntry, B eid > %(eid)s')
+            rset = self.req.execute(rql, {'eid': self.eid})
+
         if rset:
             return rset.get_entity(0,0)
 
     def previous_entity(self):
-        rql = ('Any B ORDERBY B DESC LIMIT 1 '
-               'WHERE B is BlogEntry, B entry_of BL, BL eid %(blog)s, '
-               'B eid < %(eid)s')
-        rset = self.req.execute(rql, {'blog': self.entry_of[0].eid, 'eid': self.eid})
+        if self.entry_of:
+            rql = ('Any B ORDERBY B DESC LIMIT 1 '
+                   'WHERE B is BlogEntry, B entry_of BL, BL eid %(blog)s, '
+                   'B eid < %(eid)s')
+            rset = self.req.execute(rql, {'blog': self.entry_of[0].eid, 'eid': self.eid})
+        else:
+            rql = ('Any B ORDERBY B DESC LIMIT 1 '
+                   'WHERE B is BlogEntry, B eid < %(eid)s')
+            rset = self.req.execute(rql, {'eid': self.eid})
         if rset:
             return rset.get_entity(0,0)