[views] use has_creator when available. add cwuri facet.
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Thu, 05 Aug 2010 19:31:27 +0200
changeset 218 45510a9bb345
parent 217 fe739ada925c
child 219 852e7c11f252
[views] use has_creator when available. add cwuri facet.
views/facet.py
views/primary.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/facet.py	Thu Aug 05 19:31:27 2010 +0200
@@ -0,0 +1,7 @@
+from cubicweb.selectors import is_instance
+from cubicweb.web.facet import AttributeFacet
+
+class CWUriFacet(AttributeFacet):
+    __regid__ = 'cwuri-facet'
+    __select__ = AttributeFacet.__select__ & is_instance('BlogEntry', 'MicroBlogEntry')
+    rtype = 'cwuri'
--- a/views/primary.py	Thu Aug 05 19:30:51 2010 +0200
+++ b/views/primary.py	Thu Aug 05 19:31:27 2010 +0200
@@ -61,20 +61,37 @@
     w(u'<h1>%s</h1>' % entity.view('incontext'))
     w(u'<div class="author_date"><div>%s' %
       req.format_date(entity.creation_date))
-    creator = entity.creator
-    if creator:
-        vtitle = _('blog entries created by %s') % creator.name()
+    rql = None
+    if entity.has_creator:
+        creator = entity.has_creator[0]
+        name = creator.name
+        rql = 'Any X ORDERBY D DESC WHERE X is BlogEntry, X has_creator Y, '\
+              'Y eid %s, X creation_date D' % creator.eid
+    elif entity.creator:
+        creator = entity.creator
+        name = creator.name()
         rql = 'Any X ORDERBY D DESC WHERE X is BlogEntry, X created_by Y, '\
               'Y eid %s, X creation_date D' % creator.eid
+    if rql:
+        vtitle = _('blog entries created by %s') % name
         url = req.build_url('view', rql=rql, vtitle=vtitle, page_size=10)
         w(u' %s <a title="%s" href="%s">%s</a>' % (
-            _('by'), xml_escape(vtitle), xml_escape(url), creator.name()))
+            _('by'), xml_escape(vtitle), xml_escape(url), name))
     w(u'</div></div>')
 
 class BlogEntryPrimaryView(primary.PrimaryView):
     __select__ = is_instance('BlogEntry')
     show_attr_label = False
 
+    def render_entity_toolbox(self, entity):
+        # copy from PrimaryView
+        context = 'ctxtoolbar'
+        self.w(u'<div class="%s">' % context)
+        for comp in self._cw.vreg['toolbar'].poss_visible_objects(
+            self._cw, rset=self.cw_rset, row=self.cw_row, view=self, context=context):
+            comp.render(w=self.w, row=self.cw_row, view=self)
+        self.w(u'</div>')
+
     def render_entity_relations(self, entity):
         rset = entity.related('entry_of', 'subject')
         if rset: