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


Python Post.root方法代码示例

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


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

示例1: import_posts

# 需要导入模块: from biostar.apps.posts.models import Post [as 别名]
# 或者: from biostar.apps.posts.models.Post import root [as 别名]
def import_posts(fname, uname):

    logger.info('Extracting posts from file...')
    allposts = get_posts(fname)

    logger.info('Extracting users from file...')
    allusers = get_all_users(uname)

    post_count=0
    for single in allposts:
        uid = int(single[0])
        title = single[1]
        body = single[2]
        date = single[3]
        logger.info('Fetched post : %s' % title)

        #Getting the post user
        user = get_user(uid,allusers)

        #List to hold answer posts which could not be matched
        orphans = []

        if title.startswith('Re:'):
            try:
                ptitle = title[4:]
                parent = Post.objects.get(title=ptitle)
                post = Post(title=title, content=body, author=user, type= Post.ANSWER, creation_date=date)
                post.parent=parent
                post.root=parent
                post.save()
                post_count+=1
            except:
                post = Post(title=title, author=user, type= Post.ANSWER, content=body, creation_date=date)
                orphans.append(post)
        else:
            post = Post(title=title, content=body, author=user, type = Post.QUESTION, creation_date=date)
            post.save()
            post_count+=1


    #Now try to match posts which could not be matched before
    if orphans:
        logger.info('Matching posts which could not be matched earlier')
        for post in orphans:
            try:
                title = post.title
                ptitle = title[4:]
                parent = Post.objects.get(title__startswith=ptitle)
                post.parent=parent
                post.root=parent
                post.save()
                post_count+=1
            except:
                pass

    print post_count, ' posts created'
    logger.info('DONE!')
开发者ID:Bioconductor,项目名称:support.bioconductor.org,代码行数:59,代码来源:import_phpbb.py


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