cleanup, blog entry breadcrumbs
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 12 Oct 2009 13:08:58 +0200
changeset 129 d6f708a74260
parent 128 3e708b97e867
child 130 38eda314be39
cleanup, blog entry breadcrumbs
entities.py
--- a/entities.py	Mon Oct 12 13:08:45 2009 +0200
+++ b/entities.py	Mon Oct 12 13:08:58 2009 +0200
@@ -9,7 +9,32 @@
 
 from cubicweb.utils import todate
 from cubicweb.entities import AnyEntity, fetch_config
-from cubicweb.interfaces import ICalendarViews, ICalendarable, ISiocItem, ISiocContainer
+from cubicweb.interfaces import (ICalendarViews, ICalendarable,
+                                 ISiocItem, ISiocContainer)
+
+
+class Blog(AnyEntity):
+    """customized class for Blog entities"""
+
+    id = 'Blog'
+    __implements__ = AnyEntity.__implements__ + (ISiocContainer,)
+
+    def rss_feed_url(self):
+        if self.rss_url:
+            return self.rss_url
+        rql = ('Any E ORDERBY D DESC '
+               'WHERE E is BlogEntry, E entry_of X, X eid %s, E creation_date D'
+        return self.build_url(rql=rql % self.eid, vid='rss',
+                              vtitle=self.dc_title())
+
+    # isioc interface ##########################################################
+
+    def isioc_type(self):
+        return 'Weblog'
+
+    def isioc_items(self):
+        return self.reverse_entry_of
+
 
 class BlogEntry(AnyEntity):
     """customized class for BlogEntry entities"""
@@ -24,7 +49,11 @@
     def dc_description(self, format='text/plain'):
         return self.printable_value('content', format=format)
 
-    ## calendar interfaces ####################################################
+    def parent(self):
+        return self.entry_of and self.entry_of[0] or None
+
+    # calendar interfaces ######################################################
+
     @property
     def start(self):
         return self.creation_date
@@ -48,42 +77,21 @@
         descr = u'%s %s' % (_('posted on'), self.format_date(self.creation_date))
         return descr
 
-    # isioc interface
+    # isioc interface ##########################################################
+
     def isioc_content(self):
         return self.content
 
     def isioc_container(self):
-        rset = self.related('entry_of')
-        entity = rset.get_entity(0, 0)
-        return entity
+        return self.parent()
 
     def isioc_type(self):
         return 'BlogPost'
 
     def isioc_replies(self):
+        # XXX link to comments
         return []
 
     def isioc_topics(self):
+        # XXX link to tags, folders?
         return []
-
-
-class Blog(AnyEntity):
-    """customized class for Blog entities"""
-
-    id = 'Blog'
-    __implements__ = AnyEntity.__implements__ + (ISiocContainer,)
-
-    def rss_feed_url(self):
-        if self.rss_url:
-            return self.rss_url
-        rql = 'Any E ORDERBY D DESC WHERE E is BlogEntry, E entry_of X, X eid %s, E creation_date D' % self.eid
-        return self.build_url(rql=rql, vid='rss', vtitle=self.dc_title())
-
-    # isioc interface
-    def isioc_type(self):
-        return 'Weblog'
-
-    def isioc_items(self):
-        return self.reverse_entry_of
-
-