Exemple #1
0
    def _search(self, query, maxitemcount, pagenumber):
        catalog = component.queryUtility(ICatalog, context = self.context)
        discussCatalog = getCatalog()
        if catalog is not None:
            items = []
            for obj in catalog.searchResults(**query):
                dc = IZopeDublinCore(obj)

                comments = discussCatalog.search(content = obj)
                commentsCount = len(comments)
                if commentsCount:
                    lastComment = comments.__iter__().next()
                    lastDate = max(lastComment.date, dc.modified)
                    action = 'commented'
                    lastAuthor = lastComment.author
                else:
                    action = 'modified'
                    lastAuthor = dc.creators[-1]
                    lastDate = dc.modified

                items.append((lastDate, obj, commentsCount, action, lastAuthor))

            indFrom = (maxitemcount * pagenumber) - maxitemcount
            indTo = maxitemcount * pagenumber
            items.sort(reverse=True)
            fullLength = len(items)
            items = items[indFrom:indTo]

            return items, fullLength
    def getTaskCommits(self, task):
        """ returns comments for task """

        catalog = getCatalog()
        comments = catalog.search(contexts=(task,))[:3]

        if comments:
            result = []
            for item in comments:
                principal = getPrincipal(item.author)
                homeFolder = IPersonalSpace(principal, None)
                profileUrl = homeFolder is not None \
                        and '%s/profile/'%absoluteURL(homeFolder, self.request) or ''

                # limit text length
                text = getMultiAdapter((item, self.request), ITextAnnotation).getText(text=item.comment)

                info = {
                    'text': text,
                    'author': principal and principal.title or u'Unknown',
                    'author_url': profileUrl
                }
                result.append(info)

            return result
    def items(self):
        request = self.request
        auth = getUtility(IAuthentication)
        comments = getCatalog().search(contexts=(self.context,), approved=(True,))[:15]

        for comment in comments:
            if not comment:
                continue

            url = absoluteURL(comment.content, request)

            info = {
                'link': '%s/'%url,
                'description': comment.comment,
                'guid': '%s/#comments%s'%(url, comment.__name__),
                'pubDate': rfc822.formatdate(time.mktime(comment.date.timetuple())),
                'isPermaLink': True}

            author = u'Unknown'
            try:
                principal = auth.getPrincipal(comment.author)
                profile = IPersonalProfile(principal)
                author = profile.title
                info['author'] = u'%s (%s)'%(profile.email, author)
            except PrincipalLookupError:
                pass

            info['title'] = _(u'by ${author} on ${content}',
                              mapping={'author': author, 'content': comment.content.title})
            yield info
    def update(self):
        context = self.context
        if context is None:
            return

        catalog = getCatalog()

        if '__all__' in self.types:
            self.comments = catalog.search(contexts=(context,))[:self.number]
        else:
            self.comments = catalog.search(contexts=(context,), types=self.types)[:self.number]

        super(RecentCommentsPortlet, self).update()
Exemple #5
0
    def getComments(self, uid):
        """Return all the comments for the given object's UID"""
        ids = component.getUtility(IIntIds, context = self.context)
        obj = ids.getObject(int(uid))

        discussCatalog = getCatalog()
        return [{'depth':0,
                 'title':'',
                 'commenter': getEmailById(comment.author) or comment.author,
                 'commenttext':comment.comment,
                 'modified':comment.date,
                 'id':comment.__name__,
                 }
                for comment in discussCatalog.search(content = obj)]
def bootstrapSubscriber(ev):
    db, connection, root, portal = getInformationFromEvent(ev)
    if portal is None:
        connection.close()
        return

    def findObjectsProviding(root):
        if ISite.providedBy(root):
            yield root

        try:
            if len(getParents(root)) > 3:
                raise StopIteration()
        except TypeError:
            raise StopIteration()

        values = getattr(root, "values", None)
        if callable(values):
            for subobj in values():
                for match in findObjectsProviding(subobj):
                    yield match

    try:
        for portal in findObjectsProviding(portal):
            setSite(portal)
            try:
                try:
                    catalog = getCatalog()
                except LookupError:
                    continue
                try:
                    if len(list(catalog)) != len(list(catalog.getIndexes())):
                        logger.info("Updating Discussion Catalog Indexes... (for %s)" % portal.title)
                        catalog.clear()
                        catalog.updateIndexes()
                        logger.info("Done!")
                except ComponentLookupError:
                    continue
            finally:
                setSite(None)
    finally:
        transaction.commit()
        connection.close()