web/views/boxes.py
changeset 125 979dbe0cade3
parent 107 4fe4ce7e2544
child 142 0425ee84cfa6
equal deleted inserted replaced
107:4fe4ce7e2544 125:979dbe0cade3
    15 """
    15 """
    16 __docformat__ = "restructuredtext en"
    16 __docformat__ = "restructuredtext en"
    17 
    17 
    18 from logilab.mtconverter import html_escape
    18 from logilab.mtconverter import html_escape
    19 
    19 
    20 from cubicweb.common.selectors import rset_selector, nfentity_selector
    20 from cubicweb.common.selectors import rset_selector, nfentity_selector, onelinerset_selector
    21 from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem
    21 from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem
    22 from cubicweb.web.box import BoxTemplate, ExtResourcesBoxTemplate
    22 from cubicweb.web.box import BoxTemplate, ExtResourcesBoxTemplate
    23 
    23 
    24 _ = unicode
    24 _ = unicode
    25 
    25 
   192     order = 999
   192     order = 999
   193     need_resources = 'RSS_LOGO',
   193     need_resources = 'RSS_LOGO',
   194     visible = False
   194     visible = False
   195     
   195     
   196     def call(self, **kwargs):
   196     def call(self, **kwargs):
   197         eid = self
   197         url = html_escape(self.build_url(rql=self.limited_rql(), vid='rss'))
   198         if len(self.rset)==1:
       
   199             eid = self.rset[0][0]
       
   200             rql = 'Any E WHERE E is BlogEntry, E entry_of X, X eid %s' % eid
       
   201         else:
       
   202             rql = self.limited_rql()
       
   203         url = html_escape(self.build_url(rql=rql, vid='rss'))
       
   204         rss = self.req.external_resource('RSS_LOGO')
   198         rss = self.req.external_resource('RSS_LOGO')
   205         self.w(u'<a href="%s"><img src="%s" border="0" /></a>\n' % (url, rss))
   199         self.w(u'<a href="%s"><img src="%s" border="0" /></a>\n' % (url, rss))
       
   200 
       
   201 class EntityRSSIconBox(RSSIconBox):
       
   202     """just display the RSS icon on uniform result set for a single entity"""
       
   203     __selectors__ = RSSIconBox.__selectors__ + (onelinerset_selector,)
       
   204 
       
   205     def call(self, **kwargs):
       
   206         entity = self.entity(0, 0)
       
   207         url = entity.rss_feed_url()
       
   208         eid = entity.eid
       
   209         rss = self.req.external_resource('RSS_LOGO')
       
   210         self.w(u'<a href="%s"><img src="%s" border="0" /></a>\n' %
       
   211                (html_escape(url), rss))
   206 
   212 
   207 ## warning("schemabox ne marche plus pour le moment")
   213 ## warning("schemabox ne marche plus pour le moment")
   208 ## class SchemaBox(BoxTemplate):
   214 ## class SchemaBox(BoxTemplate):
   209 ##     """display a box containing link to list of entities by type"""
   215 ##     """display a box containing link to list of entities by type"""
   210 ##     id = 'schema_box'
   216 ##     id = 'schema_box'
   219 ##             box.append(self.mk_action(display_name(self.req, etype, 'plural'),
   225 ##             box.append(self.mk_action(display_name(self.req, etype, 'plural'),
   220 ##                                       view.url(), etype=etype))
   226 ##                                       view.url(), etype=etype))
   221 ##         if not box.is_empty():
   227 ##         if not box.is_empty():
   222 ##             box.render(self.w)
   228 ##             box.render(self.w)
   223 
   229 
   224 
       
   225 class StartupViewsBox(BoxTemplate):
   230 class StartupViewsBox(BoxTemplate):
   226     """display a box containing links to all startup views"""
   231     """display a box containing links to all startup views"""
   227     id = 'startup_views_box'
   232     id = 'startup_views_box'
   228     visible = False # disabled by default
   233     visible = False # disabled by default
   229     title = _('startup views')
   234     title = _('startup views')