# HG changeset patch # User Laure Bourgois # Date 1227285402 -3600 # Node ID 979dbe0cade3c2650cbaf29fc8035fb63bce6eb7 # Parent 4fe4ce7e25444518bdc45d70f46f2ee51335f5e5 views with rss feed diff -r 4fe4ce7e2544 -r 979dbe0cade3 entities/__init__.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 diff -r 4fe4ce7e2544 -r 979dbe0cade3 interfaces.py --- 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 + """ diff -r 4fe4ce7e2544 -r 979dbe0cade3 web/views/boxes.py --- 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'\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'\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'