# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1272034400 -7200
#      Fri Apr 23 16:53:20 2010 +0200
# Branch stable
# Node ID 18b619f80a891ab1bd881ca2e438595615970a89
# Parent  6be9ba4a4f14fe28ce68b2c2787712e428b40e84
fix comments count, closes #344883. Depends on comment 1.6.3 (fix recommends on the way)

diff --git a/__pkginfo__.py b/__pkginfo__.py
--- a/__pkginfo__.py
+++ b/__pkginfo__.py
@@ -66,9 +66,12 @@
     'Programming Language :: JavaScript',
     ]
 
-__depends_cubes__ = {}
 __depends__ = {'cubicweb': '>= 3.7.3'}
-__use__ = tuple(__depends_cubes__)
+__recommends_cubes__ = {'tag': None,
+                         'comment': '>= 1.6.3'}
+__recommends__ = {}
+for cube in __recommends_cubes__:
+    __recommends__['cubicweb-'+cube] = __recommends_cubes__[cube]
 
 # package ###
 
diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
@@ -10,6 +10,7 @@
 Package: cubicweb-blog
 Architecture: all
 Depends: cubicweb-common (>= 3.7.3)
+Suggests: cubicweb-comment (>= 1.6.3), cubicweb-tag
 Description: blog component for the CubicWeb framework
  This CubicWeb component provides blogging functionnalities.
  .
diff --git a/views/secondary.py b/views/secondary.py
--- a/views/secondary.py
+++ b/views/secondary.py
@@ -161,17 +161,21 @@
         _ = lambda ertype, form='': display_name(self._cw, ertype, form)
         reldata = []
         w = reldata.append
-        if 'comments' in self._cw.vreg.schema and \
-               'BlogEntry' in self._cw.vreg.schema.rschema('comments').objects():
-            count = self._cw.execute('Any COUNT(C) WHERE C comments B, B eid %(x)s',
-                                     {'x': entity.eid}, 'x')[0][0]
+        schema = self._cw.vreg.schema
+        if 'comments' in schema and \
+               'BlogEntry' in schema.rschema('comments').objects():
+            from cubes.comment.entities import subcomments_count
+            count = subcomments_count(entity)
             if count:
                 url = xml_escape(entity.absolute_url())
-                w(u'<a href="%s">%s %s</a>' % (url, count, _('Comment', 'plural')))
+                if count > 1:
+                    label = _('Comment', 'plural')
+                else:
+                    label = _('Comment')
+                w(u'<a href="%s">%s %s</a>' % (url, count, label))
             else:
                 w(u'%s %s' % (count, _('Comment')))
-        if 'tags' in self._cw.vreg.schema and \
-               'BlogEntry' in self._cw.vreg.schema.rschema('tags').objects():
+        if 'tags' in schema and 'BlogEntry' in schema.rschema('tags').objects():
             tag_rset = entity.related('tags', 'object')
             if tag_rset:
                 w(u'%s %s' % (_('tags', 'object'), self._cw.view('csv', tag_rset)))