BlogEntry.parent should actually be an IBreadCrumbs adapter method, also move ui only prevnext adapter to views
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 06 Aug 2010 10:12:00 +0200
changeset 224 baff8d80bfe7
parent 223 729252151dea
child 225 2b2b36ff7027
BlogEntry.parent should actually be an IBreadCrumbs adapter method, also move ui only prevnext adapter to views
entities.py
views/__init__.py
--- a/entities.py	Fri Aug 06 10:11:21 2010 +0200
+++ b/entities.py	Fri Aug 06 10:12:00 2010 +0200
@@ -52,8 +52,6 @@
         """return latest modification date of this entity"""
         return self._cw.format_date(self.creation_date, date_format=date_format)
 
-    def parent(self):
-        return self.entry_of and self.entry_of[0] or None
 
 class BlogEntryICalendarableAdapter(EntityAdapter):
     __regid__ = 'ICalendarable'
@@ -104,27 +102,3 @@
         # XXX link to tags, folders?
         return []
 
-class BlogEntryIPrevNextAdapter(EntityAdapter):
-    __regid__ = 'IPrevNext'
-    __select__ = is_instance('BlogEntry')
-
-    def next_entity(self):
-        return self._sibling_entry('ASC', '>')
-
-    def previous_entity(self):
-        return self._sibling_entry('DESC', '<')
-
-    def _sibling_entry(self, order, operator):
-        if self.entity.entry_of:
-            rql = ('Any B ORDERBY B %s LIMIT 1 '
-                   'WHERE B is BlogEntry, B entry_of BL, BL eid %%(blog)s, '
-                   'B eid %s %%(eid)s')
-            rset = self._cw.execute(rql % (order, operator),
-                                    {'blog': self.entity.entry_of[0].eid, 'eid': self.entity.eid})
-        else:
-            rql = ('Any B ORDERBY B %s LIMIT 1 '
-                   'WHERE B is BlogEntry, B eid %s %%(eid)s')
-            rset = self._cw.execute(rql % (order, operator), {'eid': self.entity.eid})
-        if rset:
-            return rset.get_entity(0,0)
-
--- a/views/__init__.py	Fri Aug 06 10:11:21 2010 +0200
+++ b/views/__init__.py	Fri Aug 06 10:12:00 2010 +0200
@@ -0,0 +1,33 @@
+from cubicweb.selectors import is_instance
+from cubicweb.view import EntityAdapter
+from cubicweb.web.views import ibreadcrumbs
+
+class BlogEntryIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
+    __select__ = is_instance('BlogEntry')
+    def parent_entity(self):
+        return self.entity.entry_of and self.entity.entry_of[0] or None
+
+
+class BlogEntryIPrevNextAdapter(EntityAdapter):
+    __regid__ = 'IPrevNext'
+    __select__ = is_instance('BlogEntry')
+
+    def next_entity(self):
+        return self._sibling_entry('ASC', '>')
+
+    def previous_entity(self):
+        return self._sibling_entry('DESC', '<')
+
+    def _sibling_entry(self, order, operator):
+        if self.entity.entry_of:
+            rql = ('Any B ORDERBY B %s LIMIT 1 '
+                   'WHERE B is BlogEntry, B entry_of BL, BL eid %%(blog)s, '
+                   'B eid %s %%(eid)s')
+            rset = self._cw.execute(rql % (order, operator),
+                                    {'blog': self.entity.entry_of[0].eid, 'eid': self.entity.eid})
+        else:
+            rql = ('Any B ORDERBY B %s LIMIT 1 '
+                   'WHERE B is BlogEntry, B eid %s %%(eid)s')
+            rset = self._cw.execute(rql % (order, operator), {'eid': self.entity.eid})
+        if rset:
+            return rset.get_entity(0,0)