Beispiel #1
0
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*list(item.keys()))[0]
            path = item[pathkey]
            obj = self.context.unrestrictedTraverse(
                str(path).lstrip("/"), None)
            # path doesn't exist
            if obj is None:
                yield item
                continue
            discussion = item.get("discussions", [])
            if not discussion:
                yield item
                continue

            id_map = {}
            conversation = IConversation(obj)

            # remove all comments to avoid duplication when override is disabled  # noqa
            if list(conversation.items()):
                comments_id = [x[0] for x in conversation.items()]
                for value in comments_id:
                    try:
                        del conversation[value]
                    except Exception:
                        logger.warning(
                            "WARNING: Discussion with id {0} not found".
                            format(  # noqa
                                value))
                        pass

            for comment in discussion:
                new_comment = CommentFactory()

                new_comment.text = comment.get("text")
                new_comment.creator = comment.get("creator")
                new_comment.author_name = comment.get("author_name")
                new_comment.author_username = comment.get("author_username")
                new_comment.author_email = comment.get("author_email")
                new_comment.in_reply_to = id_map.get(
                    comment.get("in_reply_to"), 0)
                new_comment.mime_type = comment.get("mime_type")
                new_comment._owner = comment.get("_owner")
                new_comment.__ac_local_roles__ = comment.get(
                    "__ac_local_roles__")
                new_comment.user_notification = comment.get(
                    "user_notification")
                new_comment.creation_date = DateTime(
                    comment.get("creation_date")).asdatetime()
                new_comment.modification_date = DateTime(
                    comment.get("modification_date")).asdatetime()

                conversation.addComment(new_comment)

                comment_wf = new_comment.workflow_history.data.get(
                    "comment_review_workflow")
                if comment_wf:
                    new_comment.workflow_history.data.get(
                        "comment_review_workflow")[  # noqa
                            0]["review_state"] = comment["status"]

                id_map.update(
                    {comment.get("comment_id"): int(new_comment.comment_id)})

                logger.info(("Added comment with id {0} to item {1}".format(
                    new_comment.comment_id, obj.absolute_url())))
            yield item