fix prev_next adapter for BlogEntry
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Thu, 19 Sep 2013 18:15:25 +0200
changeset 329 8ba9dab9e67f
parent 328 8a27cc7d9815
child 330 ab899bd31748
fix prev_next adapter for BlogEntry Only yield (Micro)BlogEntries. Closes #3155851.
test/unittest_blog.py
views/__init__.py
--- a/test/unittest_blog.py	Thu Feb 13 17:33:44 2014 +0100
+++ b/test/unittest_blog.py	Thu Sep 19 18:15:25 2013 +0200
@@ -51,5 +51,19 @@
         self.assertEqual(xml.count("toto"), 0)
         self.assertEqual(xml.count("tutu"), content.count("tutu"))
 
+
+    def test_prevnext(self):
+        req = self.request()
+        e1 = req.create_entity('BlogEntry', title=u'a', content=u'a')
+        e2 = req.create_entity('CWGroup', name=u'NotTheNextOfe1')
+        e3 = req.create_entity('BlogEntry', title=u'b', content=u'b')
+        self.commit()
+        a1 = e1.cw_adapt_to('IPrevNext')
+        self.assertNone(a1.previous_entity())
+        self.assertEqual(u'b', a1.next_entity().title)
+        a3 = e3.cw_adapt_to('IPrevNext')
+        self.assertEqual(u'a', a3.previous_entity().title)
+        self.assertNone(a3.next_entity())
+
 if __name__ == '__main__':
     unittest_main()
--- a/views/__init__.py	Thu Feb 13 17:33:44 2014 +0100
+++ b/views/__init__.py	Thu Sep 19 18:15:25 2013 +0200
@@ -29,7 +29,8 @@
                                      'eid': self.entity.eid})
         else:
             rql = ('Any B ORDERBY B %s LIMIT 1 '
-                   'WHERE B eid %s %%(eid)s, NOT B entry_of BL')
+                   'WHERE B eid %s %%(eid)s, NOT B entry_of BL, '
+                   'B is ET, ET name IN ("BlogEntry", "MicroBlogEntry")')
             rset = self._cw.execute(rql % (order, operator),
                                     {'eid': self.entity.eid})
         if rset: