[CMF-checkins] CVS: CMF - DiscussionItem.py:1.17
Jens Vagelpohl
jens@digicool.com
Wed, 11 Jul 2001 17:46:36 -0400 (EDT)
Update of /cvs-repository/CMF/CMFDefault
In directory korak.digicool.com:/tmp/cvs-serv18884
Modified Files:
DiscussionItem.py
Log Message:
Changes to simplify hasReplies and introducing a method to count replies:
- hasReplies takes a new argument, content_obj, and will be accurate from any
content object or discussion item it is called with. it now returns a simple
boolean "1" or "0"
- replyCount, using the content_obj argument to know where to start looking,
computes the exact number of all replies to this particular object, including
nested replies.
replyCount is available with the "View" permission but is currently not used in the
standard CMF skins because there might be a performance impact with large
discussions.
--- Updated File DiscussionItem.py in package CMF --
--- DiscussionItem.py 2001/07/10 15:05:47 1.16
+++ DiscussionItem.py 2001/07/11 21:46:36 1.17
@@ -336,11 +336,41 @@
return id
security.declareProtected( CMFCorePermissions.View, 'hasReplies' )
- def hasReplies( self ):
+ def hasReplies( self, content_obj ):
"""
Test to see if there are any dicussion items
"""
- return len( self._container )
+ outer = self._getDiscussable( outer=1 )
+ if content_obj == outer:
+ return not not len( self._container )
+ else:
+ return not not len( content_obj.talkback._getReplyResults() )
+
+ security.declareProtected( CMFCorePermissions.View, 'replyCount' )
+ def replyCount( self, content_obj ):
+ """ How many replies do i have? """
+ outer = self._getDiscussable( outer=1 )
+ if content_obj == outer:
+ return len( self._container )
+ else:
+ replies = content_obj.talkback.getReplies()
+ return self._repcount( replies )
+
+ security.declarePrivate('_repcount')
+ def _repcount( self, replies ):
+ """ counts the total number of replies by recursing thru the various levels
+ """
+ count = 0
+
+ for reply in replies:
+ count = count + 1
+
+ #if there is at least one reply to this reply
+ replies = reply.talkback.getReplies()
+ if replies:
+ count = count + self._repcount( replies )
+
+ return count
security.declareProtected( CMFCorePermissions.View, 'getReplies' )
def getReplies( self ):