本文整理汇总了Python中askbot.models.Post.save方法的典型用法代码示例。如果您正苦于以下问题:Python Post.save方法的具体用法?Python Post.save怎么用?Python Post.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类askbot.models.Post
的用法示例。
在下文中一共展示了Post.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_posts
# 需要导入模块: from askbot.models import Post [as 别名]
# 或者: from askbot.models.Post import save [as 别名]
def import_posts(self, post_type, save_redirects=False):
"""imports osqa Nodes to askbot Post objects"""
if save_redirects:
redirects_file = self.open_unique_file('question_redirects')
models_map = {
'question': 'forum.question',
'answer': 'forum.answer',
'comment': 'forum.comment'
}
model_name = models_map[post_type]
for osqa_node in self.get_objects_for_model(model_name):
if osqa_node.node_type != post_type:
continue
post = Post()
#this line is a bit risky, but should work if we import things in correct order
if osqa_node.parent:
post.parent = self.get_imported_object_by_old_id(Post, osqa_node.parent)
post.thread = post.parent.thread
else:
post.thread = self.get_imported_object_by_old_id(Thread, osqa_node.id)
post.post_type = osqa_node.node_type
if save_redirects:
slug = django_urlquote(slugify(osqa_node.title))
#todo: add i18n to the old url
old_url = '/questions/%d/%s/' % (osqa_node.id, slug)
post.author = self.get_imported_object_by_old_id(User, osqa_node.author)
post.html = HTMLParser().unescape(osqa_node.body)
post.summary = post.get_snippet()
#these don't have direct equivalent in the OSQA Node object
#post.deleted_by
#post.locked_by
#post.last_edited_by
#these are to be set later with the real values
post.points = 0
post.vote_up_count = 0
post.vote_down_count = 0
post.offensive_flag_count = 0
post.save()
if save_redirects:
new_url = post.get_absolute_url()
self.write_redirect(old_url, new_url, redirects_file)
self.log_action_with_old_id(osqa_node.id, post)
if save_redirects:
redirects_file.close()
示例2: import_posts
# 需要导入模块: from askbot.models import Post [as 别名]
# 或者: from askbot.models.Post import save [as 别名]
def import_posts(self, post_type, save_redirects=False):
"""imports osqa Nodes to askbot Post objects"""
if save_redirects:
redirects_file = self.open_unique_file('question_redirects')
models_map = {
'question': 'forum.question',
'answer': 'forum.answer',
'comment': 'forum.comment'
}
model_name = models_map[post_type]
for osqa_node in self.get_objects_for_model(model_name):
#we iterate through all nodes, but pick only the ones we need
if osqa_node.node_type != post_type:
continue
#cheat: do not import deleted content
if '(deleted)' in osqa_node.state_string:
continue
post = Post()
#this line is a bit risky, but should work if we import things in correct order
if osqa_node.parent:
post.parent = self.get_imported_object_by_old_id(Post, osqa_node.parent)
if post.parent is None:
continue #deleted parent
post.thread = post.parent.thread
else:
post.thread = self.get_imported_object_by_old_id(Thread, osqa_node.id)
if post.thread is None:
continue #deleted thread
post.post_type = osqa_node.node_type
post.added_at = osqa_node.added_at
if save_redirects:
slug = django_urlquote(slugify(osqa_node.title))
#todo: add i18n to the old url
old_url = '/questions/%d/%s/' % (osqa_node.id, slug)
post.author = self.get_imported_object_by_old_id(User, osqa_node.author)
#html will de added with the revisions
#post.html = HTMLParser().unescape(osqa_node.body)
post.summary = post.get_snippet()
#these don't have direct equivalent in the OSQA Node object
#post.deleted_by - deleted nodes are not imported
#post.locked_by
#post.last_edited_by
#these are to be set later with the real values
post.points = 0
post.vote_up_count = 0
post.vote_down_count = 0
post.offensive_flag_count = 0
post.save()
#mark accepted answer
now = timezone.now()
if osqa_node.node_type == 'answer':
if '(accepted)' in osqa_node.state_string:
post.thread.accepted_answer = post
post.endorsed = True
post.endorsed_at = now
post.thread.save()
if save_redirects:
new_url = post.get_absolute_url()
self.write_redirect(old_url, new_url, redirects_file)
self.log_action_with_old_id(osqa_node.id, post)
if save_redirects:
redirects_file.close()