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


Python Topic.forum_id方法代码示例

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


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

示例1: createall

# 需要导入模块: from flaskbb.forum.models import Topic [as 别名]
# 或者: from flaskbb.forum.models.Topic import forum_id [as 别名]

#.........这里部分代码省略.........
            'editpost': False,
            'deletepost': False,
            'deletetopic': False,
            'posttopic': False,
            'postreply': False,
            'viewtopic': False,
            'viewprofile': False
        }),
        ('Guest', {
            'description': 'The Guest Group',
            'admin': False,
            'super_mod': False,
            'mod': False,
            'banned': False,
            'guest': True,
            'editpost': False,
            'deletepost': False,
            'deletetopic': False,
            'posttopic': False,
            'postreply': False,
            'viewtopic': False,
            'viewprofile': False
        })
    ))

    # create 5 groups
    for key, value in groups.items():
        group = Group(name=key)

        for k, v in value.items():
            setattr(group, k, v)

        db.session.add(group)
        db.session.commit()

    # create 5 users
    groups = Group.query.all()
    for u in range(1, 6):
        username = "test%s" % u
        email = "test%[email protected]" % u
        user = User(username=username, password="test", email=email)
        user.secondary_groups.append(groups[u-1])
        user.primary_group_id = u
        db.session.add(user)
        db.session.commit()

    # create 2 categories
    for i in range(1, 3):
        category_title = "Test Category %s" % i
        category = Forum(is_category=True, title=category_title,
                         description="Test Description")
        db.session.add(category)

        # create 2 forums in each category
        for j in range(1, 3):
            if i == 2:
                j += 2

            forum_title = "Test Forum %s %s" % (j, i)
            forum = Forum(title=forum_title, description="Test Description",
                          parent_id=i)
            db.session.add(forum)
        db.session.commit()

    # create 1 topic in each forum
    for k in [2, 3, 5, 6]:  # Forum ids are not sequential because categories.
        topic = Topic()
        first_post = Post()

        topic.title = "Test Title %s" % k
        topic.user_id = 1
        topic.forum_id = k
        db.session.add(topic)
        db.session.commit()

        first_post.content = "Test Content"
        first_post.user_id = 1
        first_post.topic_id = topic.id
        db.session.add(first_post)
        db.session.commit()

        # Invalidate relevant caches
        topic.invalidate_cache()
        topic.forum.invalidate_cache()

        # create 2 additional posts for each topic
        for m in range(1, 3):
            post = Post(content="Test Post", user_id=2, topic_id=k)

            db.session.add(post)
            db.session.commit()

            # Update the post count
            post.user.invalidate_cache()
            topic.invalidate_cache()
            topic.forum.invalidate_cache()

            db.session.commit()

    db.session.commit()
开发者ID:RJacksonm1,项目名称:flaskbb,代码行数:104,代码来源:manage.py


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