def __iter__(self):
        for item in self.previous:

            if item['_type'] == 'Discussion Item':
                content, conversation, comment_id = item['_path'].rsplit('/', 2)
                content_item = self._traverse(content)
                if content_item is not None:
                    comment = Comment()
                    date = item.get('effective_date')
                    date_obj = DateTime(date).asdatetime()
                    comment.comment_id = int(comment_id)
                    #comment.creation_date = comment.modification_date = date_obj
                    comment.text = item.get('text')
                    comment.mime_type = item.get('text_format')
                    # XXX
                    comment.author_name = item.get('_owner')
                    adapted = IConversation(content_item)
                    adapted.addComment(comment)
                    self.logger.info('Comment added {}'.format(comment_id))

            yield item
Exemple #2
0
    def import_data(self, data):
        results = 0
        for conversation_data in data:
            obj = api.content.get(UID=conversation_data["uuid"])
            if not obj:
                continue
            if not obj.restrictedTraverse("@@conversation_view").enabled():
                continue
            added = 0
            conversation = IConversation(obj)

            for item in conversation_data["conversation"]["items"]:

                if isinstance(item["text"], dict) and item["text"].get("data"):
                    item["text"] = item["text"]["data"]

                comment = Comment()
                comment_id = int(item["comment_id"])
                comment.comment_id = comment_id
                comment.creation_date = dateutil.parser.parse(
                    item["creation_date"])
                comment.modification_date = dateutil.parser.parse(
                    item["modification_date"])
                comment.author_name = item["author_name"]
                comment.author_username = item["author_username"]
                comment.creator = item["author_username"]
                comment.text = unescape(item["text"].replace(
                    u"\r<br />", u"\r\n").replace(u"<br />", u"\r\n"))

                if item["user_notification"]:
                    comment.user_notification = True
                if item.get("in_reply_to"):
                    comment.in_reply_to = int(item["in_reply_to"])

                conversation._comments[comment_id] = comment
                comment.__parent__ = aq_base(conversation)
                commentator = comment.author_username
                if commentator:
                    if commentator not in conversation._commentators:
                        conversation._commentators[commentator] = 0
                    conversation._commentators[commentator] += 1

                reply_to = comment.in_reply_to
                if not reply_to:
                    # top level comments are in reply to the faux id 0
                    comment.in_reply_to = reply_to = 0

                if reply_to not in conversation._children:
                    conversation._children[reply_to] = LLSet()
                conversation._children[reply_to].insert(comment_id)

                # Add the annotation if not already done
                annotions = IAnnotations(obj)
                if DISCUSSION_ANNOTATION_KEY not in annotions:
                    annotions[DISCUSSION_ANNOTATION_KEY] = aq_base(
                        conversation)
                added += 1
            logger.info("Added {} comments to {}".format(
                added, obj.absolute_url()))
            results += added

        return results
 def test_pacomment_text(self):
     comment = Comment()
     comment.text = u'Foo bar baz'
     adapter = ITextExtractor(comment)
     self.assertEqual(adapter.text, 'Foo bar baz')
 def test_pacomment_text(self):
     comment = Comment()
     comment.text = u'Foo bar baz'
     adapter = ITextExtractor(comment)
     self.assertEqual(adapter.text, 'Foo bar baz')