fix comments count, closes #344883. Depends on comment 1.6.3 (fix recommends on the way) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 23 Apr 2010 16:53:20 +0200
branchstable
changeset 196 18b619f80a89
parent 195 6be9ba4a4f14
child 197 a149c357550b
fix comments count, closes #344883. Depends on comment 1.6.3 (fix recommends on the way)
__pkginfo__.py
debian/control
views/secondary.py
--- a/__pkginfo__.py	Fri Apr 23 16:11:19 2010 +0200
+++ b/__pkginfo__.py	Fri Apr 23 16:53:20 2010 +0200
@@ -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 ###
 
--- a/debian/control	Fri Apr 23 16:11:19 2010 +0200
+++ b/debian/control	Fri Apr 23 16:53:20 2010 +0200
@@ -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.
  .
--- a/views/secondary.py	Fri Apr 23 16:11:19 2010 +0200
+++ b/views/secondary.py	Fri Apr 23 16:53:20 2010 +0200
@@ -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)))