views with rss feed
authorLaure Bourgois <Laure.Bourgois@logilab.fr>
Fri, 21 Nov 2008 17:36:42 +0100
changeset 125 979dbe0cade3
parent 107 4fe4ce7e2544
child 126 80c65c9f7c41
views with rss feed
entities/__init__.py
interfaces.py
web/views/boxes.py
--- a/entities/__init__.py	Thu Nov 20 11:51:28 2008 +0100
+++ b/entities/__init__.py	Fri Nov 21 17:36:42 2008 +0100
@@ -16,7 +16,8 @@
 from cubicweb.common.entity import Entity
 from cubicweb.schema import FormatConstraint
 
-from cubicweb.interfaces import IBreadCrumbs
+from cubicweb.interfaces import IBreadCrumbs, IFeed
+
 
 class AnyEntity(Entity):
     """an entity instance has e_schema automagically set on the class and
@@ -52,7 +53,7 @@
         ('comments',           '*', 'object')  : ('generated', 'link'),
         }
 
-    __implements__ = (IBreadCrumbs,)
+    __implements__ = (IBreadCrumbs, IFeed)
     
     @classmethod
     def selected(cls, etype):
@@ -197,6 +198,10 @@
                 path.append( self.req._(view.title) )
         return path
 
+    ## IFeed interface ########################################################
+
+    def rss_feed_url(self):
+        return self.absolute_url(vid='rss')
     # abstractions making the whole things (well, some at least) working ######
     
     @classmethod
--- a/interfaces.py	Thu Nov 20 11:51:28 2008 +0100
+++ b/interfaces.py	Fri Nov 21 17:36:42 2008 +0100
@@ -232,3 +232,9 @@
         (returns None for default)
         """
         
+class IFeed(Interface):
+    """interface for entities with rss flux"""
+    
+    def rss_feed_url(self):
+        """return an url which layout sub-entities item
+        """
--- a/web/views/boxes.py	Thu Nov 20 11:51:28 2008 +0100
+++ b/web/views/boxes.py	Fri Nov 21 17:36:42 2008 +0100
@@ -17,7 +17,7 @@
 
 from logilab.mtconverter import html_escape
 
-from cubicweb.common.selectors import rset_selector, nfentity_selector
+from cubicweb.common.selectors import rset_selector, nfentity_selector, onelinerset_selector
 from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem
 from cubicweb.web.box import BoxTemplate, ExtResourcesBoxTemplate
 
@@ -194,16 +194,22 @@
     visible = False
     
     def call(self, **kwargs):
-        eid = self
-        if len(self.rset)==1:
-            eid = self.rset[0][0]
-            rql = 'Any E WHERE E is BlogEntry, E entry_of X, X eid %s' % eid
-        else:
-            rql = self.limited_rql()
-        url = html_escape(self.build_url(rql=rql, vid='rss'))
+        url = html_escape(self.build_url(rql=self.limited_rql(), vid='rss'))
         rss = self.req.external_resource('RSS_LOGO')
         self.w(u'<a href="%s"><img src="%s" border="0" /></a>\n' % (url, rss))
 
+class EntityRSSIconBox(RSSIconBox):
+    """just display the RSS icon on uniform result set for a single entity"""
+    __selectors__ = RSSIconBox.__selectors__ + (onelinerset_selector,)
+
+    def call(self, **kwargs):
+        entity = self.entity(0, 0)
+        url = entity.rss_feed_url()
+        eid = entity.eid
+        rss = self.req.external_resource('RSS_LOGO')
+        self.w(u'<a href="%s"><img src="%s" border="0" /></a>\n' %
+               (html_escape(url), rss))
+
 ## warning("schemabox ne marche plus pour le moment")
 ## class SchemaBox(BoxTemplate):
 ##     """display a box containing link to list of entities by type"""
@@ -221,7 +227,6 @@
 ##         if not box.is_empty():
 ##             box.render(self.w)
 
-
 class StartupViewsBox(BoxTemplate):
     """display a box containing links to all startup views"""
     id = 'startup_views_box'