Exemplo n.º 1
0
    def getKeyedForums(self, sitewide=False):
        """Return all the forums in a board."""
        catalog = getToolByName(self.context, 'portal_catalog')
        query = {'object_provides': IForum.__identifier__}
        if not sitewide:
            query['path'] = '/'.join(self.context.getPhysicalPath())

        result = {}

        for f in catalog(query):
            obj = f._unrestrictedGetObject()
            data = dict(
                absolute_url=f.getURL(),
                Title=f.Title,
                Description=f.Description,
                getNumberOfConversations=getNumberOfConversations(
                    obj, catalog
                ),  # XXX THIS AND CATEGORY IS WHY WE NEED GETOBJECT, TRY CACHING
                getLastCommentDate=None,
                getLastCommentAuthor=None,
            )

            lastcomment = catalog(object_provides=IComment.__identifier__,
                                  sort_on='created',
                                  sort_order='reverse',
                                  sort_limit=1,
                                  path='/'.join(obj.getPhysicalPath()))
            if lastcomment:
                lastcomment = lastcomment[0]
                data['getLastCommentDate'] = self.toPloneboardTime(
                    lastcomment.created)
                data['getLastCommentAuthor'] = lastcomment.Creator

            try:
                categories = obj.getCategory()
            except AttributeError:
                categories = None
            if not categories:
                categories = None
            if not isinstance(categories, (tuple, list)):
                categories = categories,
            for category in categories:
                try:
                    categoryforums = result.get(category, [])
                    categoryforums.append(data)
                    result[category] = categoryforums
                except TypeError:  # category is list?!
                    result[', '.join(category)] = data
        return result
Exemplo n.º 2
0
    def getKeyedForums(self, sitewide=False):
        """Return all the forums in a board."""
        catalog = getToolByName(self.context, 'portal_catalog')
        query = {'object_provides':IForum.__identifier__}
        if not sitewide:
            query['path'] = '/'.join(self.context.getPhysicalPath())

        result = {}

        for f in catalog(query):
            obj = f._unrestrictedGetObject()
            data = dict(absolute_url=f.getURL(),
                        Title=f.Title,
                        Description=f.Description,
                        getNumberOfConversations=getNumberOfConversations(obj, catalog), # XXX THIS AND CATEGORY IS WHY WE NEED GETOBJECT, TRY CACHING
                        getLastCommentDate=None,
                        getLastCommentAuthor=None,
                        )

            lastcomment = catalog(object_provides=IComment.__identifier__,
                                  sort_on='created',
                                  sort_order='reverse',
                                  sort_limit=1,
                                  path='/'.join(obj.getPhysicalPath()))
            if lastcomment:
                lastcomment = lastcomment[0]
                data['getLastCommentDate'] = self.toPloneboardTime(lastcomment.created)
                data['getLastCommentAuthor'] = lastcomment.Creator


            try:
                categories = obj.getCategory()
            except AttributeError:
                categories = None
            if not categories:
                categories = None
            if not isinstance(categories, (tuple,list)):
                categories = categories,
            for category in categories:
                try:
                    categoryforums = result.get(category, [])
                    categoryforums.append(data)
                    result[category] = categoryforums
                except TypeError: # category is list?!
                    result[', '.join(category)] = data
        return result
Exemplo n.º 3
0
 def getNumberOfConversations(self):
     """Returns the number of conversations in this forum."""
     return getNumberOfConversations(self.context, self.catalog)