Skip to content
Snippets Groups Projects
Commit 45510a9bb345 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[views] use has_creator when available. add cwuri facet.

parent fe739ada925c
No related branches found
No related tags found
No related merge requests found
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'
......@@ -61,8 +61,14 @@
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
......@@ -67,4 +73,6 @@
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>' % (
......@@ -69,9 +77,9 @@
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
......@@ -72,9 +80,18 @@
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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment