Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / Discussion

Discussion

早期 plone.commenting 範例

# plone.app.discussion/interfaces.py
from zope.interface.common.mapping import IIterableMapping

generator

# plone.app.discussion/conversation.py
  def getThreads(self, start=0, size=None, root=0, depth=None):
      """Get threaded comments
      """
      def recurse(comment_id, d=0):
          # Yield the current comment before we look for its children
          yield {'id': comment_id, 'comment': self[comment_id], 'depth': d}

          # Recurse if there are children and we are not out of our depth
          if depth is None or d + 1 < depth:
              children = self._children.get(comment_id, None)
              if children is not None:
                  for child_id in children:
                      for value in recurse(child_id, d + 1):
                          yield value