Skip to content
Snippets Groups Projects
Commit acc20451d14b authored by Arthur Lutz's avatar Arthur Lutz
Browse files

Addition context views for navigation boxes (closes #1529146)

parent bb889339826f
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,6 @@
from cubicweb.web import component
class BlogArchivesBox(component.EntityCtxComponent):
class BlogArchivesBox(component.CtxComponent):
"""blog side box displaying a Blog Archive"""
__regid__ = 'blog.archives_by_date'
......@@ -19,6 +19,6 @@
"""blog side box displaying a Blog Archive"""
__regid__ = 'blog.archives_by_date'
__select__ = (component.EntityCtxComponent.__select__
__select__ = (component.CtxComponent.__select__
& is_instance('Blog', 'MicroBlog')
& has_related_entities('entry_of', 'object'))
title = _('blog.archives_by_date')
......@@ -26,5 +26,7 @@
context = 'left'
def render_body(self, w):
rset = self.entity.related('entry_of', 'object')
#FIXME doesn't handle (yet) multiple blogs
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
rset = entity.related('entry_of', 'object')
self._cw.view('cw.archive.by_date', rset, maxentries=6,
......@@ -30,5 +32,5 @@
self._cw.view('cw.archive.by_date', rset, maxentries=6,
basepath=self.entity.rest_path() + '/blogentries',
basepath=entity.rest_path() + '/blogentries',
w=w)
......@@ -32,5 +34,17 @@
w=w)
class BlogByAuthorBox(component.EntityCtxComponent):
class BlogEntryArchivesBox(BlogArchivesBox):
__regid__ = 'blog.entry_archives_by_date'
__select__ = (component.CtxComponent.__select__
& is_instance('BlogEntry', 'MicroBlogEntry')
& has_related_entities('entry_of', 'subject'))
def render_body(self, w):
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
box = self._cw.vreg['ctxcomponents'].select('blog.archives_by_date', self._cw, w=w,
rset=entity.related('entry_of', 'subject'))
box.render_body(w)
class BlogByAuthorBox(component.CtxComponent):
__regid__ = 'blog.archives_by_author'
......@@ -36,9 +50,9 @@
__regid__ = 'blog.archives_by_author'
__select__ = (component.EntityCtxComponent.__select__
& is_instance('Blog', 'MicroBlogEntry')
__select__ = (component.CtxComponent.__select__
& is_instance('Blog', 'MicroBlog')
& has_related_entities('entry_of', 'object'))
title = _('blog.archives_by_author')
order = 36
context = 'left'
def render_body(self, w):
......@@ -39,8 +53,10 @@
& has_related_entities('entry_of', 'object'))
title = _('blog.archives_by_author')
order = 36
context = 'left'
def render_body(self, w):
rset = self.entity.related('entry_of', 'object')
#FIXME doesn't handle (yet) multiple blogs
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
rset = entity.related('entry_of', 'object')
self._cw.view('cw.archive.by_author', rset,
......@@ -46,5 +62,5 @@
self._cw.view('cw.archive.by_author', rset,
basepath=self.entity.rest_path() + '/blogentries',
basepath=entity.rest_path() + '/blogentries',
w=w)
......@@ -48,6 +64,18 @@
w=w)
class BlogEntryByAuthorBox(BlogByAuthorBox):
__regid__ = 'blog.entry_archives_by_author'
__select__ = (component.CtxComponent.__select__
& is_instance('BlogEntry', 'MicroBlogEntry')
& has_related_entities('entry_of', 'subject'))
def render_body(self, w):
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
box = self._cw.vreg['ctxcomponents'].select('blog.archives_by_author', self._cw, w=w,
rset=entity.related('entry_of', 'subject'))
box.render_body(w)
class LatestBlogsBox(component.CtxComponent):
"""display a box with latest blogs and rss"""
__regid__ = 'blog.latest_blogs'
......@@ -83,7 +111,11 @@
# FIXME - could use rss_url defined as a property if available
rss_label = u'%s <img src="%s" alt="%s"/>' % (
self._cw._(u'subscribe'), rss_icon, self._cw._('rss icon'))
rss_url = self._cw.build_url('view', vid='rss', rql=rql)
blogs = self._cw.execute('Any B,RSS WHERE B is Blog, B rss_url RSS')
if len(blogs) == 1:
rss_url = blogs[0][1]
else:
rss_url = self._cw.build_url('view', vid='rss', rql=rql)
w(u'<li>%s</li>\n' %
tags.a(rss_label, href=rss_url, escapecontent=False))
w(u'</ul>\n')
......@@ -103,3 +135,22 @@
'Any X,T,CD ORDERBY CD DESC LIMIT 5 WHERE '
'X title T, X creation_date CD, X entry_of B, B eid %(b)s',
{'b': blog.eid})
class LatestBlogsBlogEntryBox(LatestBlogsBox):
"""display a box with latest blogs and rss, filtered for a particular blog
"""
__select__ = (component.CtxComponent.__select__
& is_instance('BlogEntry')
& has_related_entities('entry_of', 'subject'))
display_see_more_link = False
contextual = True
def latest_blogs_rset(self):
blogentry = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
#FIXME doesn't handle (yet) multiple blogs
blog = blogentry.related('entry_of', 'subject').get_entity(0,0)
return self._cw.execute(
'Any X,T,CD ORDERBY CD DESC LIMIT 5 WHERE '
'X title T, X creation_date CD, X entry_of B, B eid %(b)s',
{'b': blog.eid})
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