# HG changeset patch # User Sylvain Thénault <sylvain.thenault@logilab.fr> # Date 1272033963 -7200 # Fri Apr 23 16:46:03 2010 +0200 # Branch stable # Node ID 69db5f062634d02963713c7bb4d6411cde9fe68a # Parent 74eb3c3bd18f3df9083706e437d4cde83e125605 make subcomments_count usable as a function taking any commentable object as argument diff --git a/entities.py b/entities.py --- a/entities.py +++ b/entities.py @@ -14,6 +14,11 @@ from cubicweb.selectors import implements from cubicweb.entities import AnyEntity, fetch_config + +def subcomments_count(commentable): + return sum([len(commentable.reverse_comments)] + + [subcomments_count(c) for c in commentable.reverse_comments]) + class Comment(TreeMixIn, AnyEntity): """customized class for Comment entities""" __regid__ = 'Comment' @@ -34,14 +39,12 @@ """ return self.root().rest_path(), {} - def subcomments_count(self): - return sum([len(self.reverse_comments)] - + [c.subcomments_count() for c in self.reverse_comments]) + subcomments_count = subcomments_count + # some views potentially needed on web *and* server side (for notification) # so put them here - class CommentFullTextView(EntityView): __regid__ = 'fulltext' __select__ = implements('Comment')