コード例 #1
0
    def sync_comment(self):
        comments_map = {}
        root_header = None
        root_comment = None

        for comment in self.comments():
            dot()
            if root_header is None or root_header.object_id != comment.nid:
                root_comment = Comment.objects.get_or_create_root_comment(
                    self.node_ctype, comment.nid)[0]
            update_comments_header(Comment, instance=root_comment)
            filters = self.formats_filtering.get(comment.format,
                                                 self.formats_filtering[1])
            filtered_comment = self.call_filters(comment.comment, filters)
            time_created = timestamp_to_time(comment.timestamp)
            comment_instance = Comment(
                parent_id=comments_map[comment.pid]
                if comment.pid else root_comment.id,
                object_id=comment.nid,
                content_type=self.node_ctype,
                subject=comment.subject,
                created=time_created,
                updated=time_created,
                user_id=self.users_map.get(comment.uid),
                user_name=comment.name,
                is_public=True,
                is_locked=root_comment.is_locked,
                original_comment=TextVal(
                    self.filter_formats.get(comment.format, 'raw') + ':' +
                    comment.comment),
            )
            comment_instance.save()
            Comment.objects.filter(pk=comment_instance.pk).update(
                filtered_comment=filtered_comment)
            comments_map[comment.cid] = comment_instance.pk
コード例 #2
0
	def sync_comment(self):
		comments_map = {}
		root_header = None
		root_comment = None

		for comment in self.comments():
			dot()
			if root_header is None or root_header.object_id != comment.nid:
				root_comment = Comment.objects.get_or_create_root_comment(self.node_ctype, comment.nid)[0]
			update_comments_header(Comment, instance=root_comment)
			filters = self.formats_filtering.get(comment.format, self.formats_filtering[1])
			filtered_comment = self.call_filters(comment.comment, filters)
			time_created = timestamp_to_time(comment.timestamp)
			comment_instance = Comment(
				parent_id=comments_map[comment.pid] if comment.pid else root_comment.id,
				object_id=comment.nid,
				content_type=self.node_ctype,
				subject=comment.subject,
				created=time_created,
				updated=time_created,
				user_id=self.users_map.get(comment.uid),
				user_name=comment.name,
				is_public=True,
				is_locked=root_comment.is_locked,
				original_comment=TextVal(self.filter_formats.get(comment.format, 'raw') + ':' + comment.comment),
			)
			comment_instance.save()
			Comment.objects.filter(pk=comment_instance.pk).update(filtered_comment=filtered_comment)
			comments_map[comment.cid] = comment_instance.pk
コード例 #3
0
 def sync_node(self):
     for node in self.nodes:
         dot()
         if Node.objects.filter(id=node.nid).exists():
             root = Comment.objects.get_or_create_root_comment(
                 self.node_ctype, node.nid)[0]
             if int(node.comment) == COMMENT_NODE_CLOSED:
                 root.is_locked = True
                 root.save()
             update_comments_header(Comment, instance=root)
             continue
         with transaction.atomic():
             node_instance = Node(
                 id=node.nid,
                 node_type=node.type,
                 title=node.title,
                 author_id=self.users_map.get(node.uid),
                 is_published=int(node.status) == NODE_PUBLISHED,
                 is_commentable=int(node.comment) != COMMENT_NODE_HIDDEN,
                 is_promoted=int(node.promote) == NODE_PROMOTED,
                 is_sticky=int(node.sticky) == NODE_STICKY,
                 revision_id=node.vid,
                 created=timestamp_to_time(node.created),
                 updated=timestamp_to_time(node.changed))
             node_instance.save()
             for revision in node.revisions:
                 body = revision.body
                 for search, replace in BLACKHOLE_BODY_REPLACE:
                     body = body.replace(search, replace)
                 filters = self.formats_filtering.get(
                     revision.format, self.formats_filtering[1])
                 filtered_body = self.call_filters(body, filters)
                 revision_instance = NodeRevision(
                     id=revision.vid,
                     node=node_instance,
                     title=revision.title,
                     author_id=self.users_map.get(node.uid),
                     original_body=TextVal(
                         self.filter_formats.get(revision.format, 'raw') +
                         ':' + body),
                     log=revision.log or '',
                     created=timestamp_to_time(revision.timestamp),
                     updated=timestamp_to_time(revision.timestamp))
                 revision_instance.save()
                 NodeRevision.objects.filter(
                     pk=revision_instance.pk).update(
                         filtered_body=filtered_body)
             for term_id in node.terms:
                 node_instance.terms.add(self.term_map[term_id])
             root = Comment.objects.get_or_create_root_comment(
                 self.node_ctype, node.nid)[0]
             if int(node.comment) == COMMENT_NODE_CLOSED:
                 root.is_locked = True
                 root.save()
             update_comments_header(Comment, instance=root)
コード例 #4
0
	def sync_node(self):
		for node in self.nodes:
			dot()
			if Node.objects.filter(id=node.nid).exists():
				root = Comment.objects.get_or_create_root_comment(self.node_ctype, node.nid)[0]
				if int(node.comment) == COMMENT_NODE_CLOSED:
					root.is_locked = True
					root.save()
				update_comments_header(Comment, instance=root)
				continue
			with transaction.atomic():
				node_instance = Node(
					id=node.nid,
					node_type=node.type,
					title=node.title,
					author_id=self.users_map.get(node.uid),
					is_published=int(node.status) == NODE_PUBLISHED,
					is_commentable=int(node.comment) != COMMENT_NODE_HIDDEN,
					is_promoted=int(node.promote) == NODE_PROMOTED,
					is_sticky=int(node.sticky) == NODE_STICKY,
					revision_id=node.vid,
					created=timestamp_to_time(node.created),
					updated=timestamp_to_time(node.changed)
				)
				node_instance.save()
				for revision in node.revisions:
					body = revision.body
					for search, replace in BLACKHOLE_BODY_REPLACE:
						body = body.replace(search, replace)
					filters = self.formats_filtering.get(revision.format, self.formats_filtering[1])
					filtered_body = self.call_filters(body, filters)
					revision_instance = NodeRevision(
						id=revision.vid,
						node=node_instance,
						title=revision.title,
						author_id=self.users_map.get(node.uid),
						original_body=TextVal(self.filter_formats.get(revision.format, 'raw') + ':' + body),
						log=revision.log or '',
						created=timestamp_to_time(revision.timestamp),
						updated=timestamp_to_time(revision.timestamp)
					)
					revision_instance.save()
					NodeRevision.objects.filter(pk=revision_instance.pk).update(filtered_body=filtered_body)
				for term_id in node.terms:
					node_instance.terms.add(self.term_map[term_id])
				root = Comment.objects.get_or_create_root_comment(self.node_ctype, node.nid)[0]
				if int(node.comment) == COMMENT_NODE_CLOSED:
					root.is_locked = True
					root.save()
				update_comments_header(Comment, instance=root)