当前位置: 首页>>代码示例>>Python>>正文


Python Post.get_snippet方法代码示例

本文整理汇总了Python中askbot.models.Post.get_snippet方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get_snippet方法的具体用法?Python Post.get_snippet怎么用?Python Post.get_snippet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在askbot.models.Post的用法示例。


在下文中一共展示了Post.get_snippet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_posts

# 需要导入模块: from askbot.models import Post [as 别名]
# 或者: from askbot.models.Post import get_snippet [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()
开发者ID:bigdognec,项目名称:askbot-devel,代码行数:60,代码来源:askbot_add_osqa_content.py

示例2: import_posts

# 需要导入模块: from askbot.models import Post [as 别名]
# 或者: from askbot.models.Post import get_snippet [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()
开发者ID:AppsDoc,项目名称:askbot-devel,代码行数:81,代码来源:askbot_add_osqa_content.py


注:本文中的askbot.models.Post.get_snippet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。