[views] ticket #343128, add a box of the number of blogs by author
authorSandrine Ribeau <sandrine.ribeau@logilab.fr>
Thu, 05 Nov 2009 14:41:26 -0800
changeset 142 d06dd0be09ce
parent 141 6102b385b8a3
child 143 3ebe83f66291
[views] ticket #343128, add a box of the number of blogs by author
views/secondary.py
--- a/views/secondary.py	Wed Nov 04 17:01:42 2009 -0800
+++ b/views/secondary.py	Thu Nov 05 14:41:26 2009 -0800
@@ -13,7 +13,8 @@
 
 from cubicweb.schema import display_name
 from cubicweb.view import EntityView, StartupView
-from cubicweb.selectors import paginated_rset, sorted_rset, implements
+from cubicweb.selectors import paginated_rset, sorted_rset, implements, \
+                               authenticated_user
 from cubicweb.web.htmlwidgets import BoxLink, BoxWidget
 from cubicweb.web.views import baseviews, boxes, calendar, navigation
 
@@ -120,6 +121,20 @@
         box.append(BoxLink(rss_url, rss_label))
         box.render(self.w)
 
+class BlogEntrySummary(boxes.BoxTemplate):
+    id = 'blog_summary_box'
+    title = _('boxes_blog_summary_box')
+    order = 36
+    __select__ = boxes.BoxTemplate.__select__ & authenticated_user()
+
+    def call(self, view=None, **kwargs):
+        box = BoxWidget(self.req._(self.title), self.id, islist=True)
+        rql = 'Any FN, SN, L, COUNT(B) GROUPBY L, SN, FN WHERE U is CWUser, U firstname FN, ' \
+              'U surname SN, U login L, B is BlogEntry, B created_by U'
+        rset = self.req.execute(rql)
+        for user in rset:
+            box.append(BoxLink(self.build_url('blogentry/%s' % user[2]), u'%s %s [%s]' % (user[0], user[1], user[3])))
+        box.render(self.w)
 
 ## list views ##################################################################