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


Python Forum.save方法代码示例

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


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

示例1: test_forum_save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def test_forum_save(category, moderator_user):
    """Test the save forum method"""
    forum = Forum(title="Test Forum", category_id=category.id)
    forum.moderators = [moderator_user]
    forum.save()

    assert forum.title == "Test Forum"
    assert forum.moderators == [moderator_user]
开发者ID:0xsKu,项目名称:flaskbb,代码行数:10,代码来源:test_forum_models.py

示例2: test_topic_merge_other_forum

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def test_topic_merge_other_forum(topic):
    """You cannot merge a topic with a topic from another forum."""
    forum_other = Forum(title="Test Forum 2", category_id=1)
    forum_other.save()

    topic_other = Topic(title="Test Topic 2")
    post_other = Post(content="Test Content 2")
    topic_other.save(user=topic.user, forum=forum_other, post=post_other)

    assert not topic.merge(topic_other)
开发者ID:PPPython,项目名称:flaskbb,代码行数:12,代码来源:test_forum_models.py

示例3: test_forum_save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def test_forum_save(category, moderator_user):
    forum = Forum(title="Test Forum", category_id=category.id)
    forum.save()

    assert forum.title == "Test Forum"

    # Test with adding a moderator
    forum.save([moderator_user])

    for moderator in forum.moderators:
        assert moderator == moderator_user
开发者ID:hugleecool,项目名称:flaskbb,代码行数:13,代码来源:test_forum_models.py

示例4: test_topic_move

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def test_topic_move(topic_normal):
    forum_other = Forum(title="Test Forum 2", category_id=1)
    forum_other.save()

    forum_old = Forum.query.filter_by(id=topic_normal.forum_id).first()

    assert topic_normal.move(forum_other)

    assert forum_old.topics == []

    assert forum_old.topic_count == 0
    assert forum_old.post_count == 0

    assert forum_other.topic_count == 1
    assert forum_other.post_count == 1
开发者ID:hugleecool,项目名称:flaskbb,代码行数:17,代码来源:test_forum_models.py

示例5: create_test_data

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def create_test_data():
    """
    Creates 5 users, 2 categories and 2 forums in each category. It also opens
    a new topic topic in each forum with a post.
    """
    create_default_groups()
    create_default_settings()

    # create 5 users
    for u in range(1, 6):
        username = "test%s" % u
        email = "test%[email protected]" % u
        user = User(username=username, password="test", email=email)
        user.primary_group_id = u
        user.save()

    user1 = User.query.filter_by(id=1).first()
    user2 = User.query.filter_by(id=2).first()

    # create 2 categories
    for i in range(1, 3):
        category_title = "Test Category %s" % i
        category = Category(title=category_title,
                            description="Test Description")
        category.save()

        # 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",
                          category_id=i)
            forum.save()

            # create a topic
            topic = Topic()
            post = Post()

            topic.title = "Test Title %s" % j
            post.content = "Test Content"
            topic.save(post=post, user=user1, forum=forum)

            # create a second post in the forum
            post = Post()
            post.content = "Test Post"
            post.save(user=user2, topic=topic)
开发者ID:aregsar,项目名称:flaskbb,代码行数:50,代码来源:populate.py

示例6: save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
 def save(self):
     data = self.data
     # delete submit and csrf_token from data
     data.pop('submit', None)
     data.pop('csrf_token', None)
     forum = Forum(**data)
     return forum.save()
开发者ID:eirnym,项目名称:flaskbb,代码行数:9,代码来源:forms.py

示例7: save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
 def save(self):
     data = self.data
     # remove the button
     data.pop('submit', None)
     forum = Forum(**data)
     # flush SQLA info from created instance so that it can be merged
     return forum.save()
开发者ID:SeanChen0617,项目名称:flaskbb,代码行数:9,代码来源:forms.py

示例8: test_topic_move

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def test_topic_move(topic):
    """Tests the topic move method."""
    forum_other = Forum(title="Test Forum 2", category_id=1)
    forum_other.save()

    forum_old = Forum.query.filter_by(id=topic.forum_id).first()

    assert topic.move(forum_other)

    assert forum_old.topics.all() == []
    assert forum_old.last_post_id is None

    assert forum_old.topic_count == 0
    assert forum_old.post_count == 0

    assert forum_other.last_post_id == topic.last_post_id
    assert forum_other.topic_count == 1
    assert forum_other.post_count == 1
开发者ID:0xsKu,项目名称:flaskbb,代码行数:20,代码来源:test_forum_models.py

示例9: save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
    def save(self):
        data = self.data
        # remove the button
        data.pop('submit', None)
        forum = Forum(**data)
        # flush SQLA info from created instance so that it can be merged
        make_transient(forum)
        make_transient_to_detached(forum)

        return forum.save()
开发者ID:abshkd,项目名称:flaskbb,代码行数:12,代码来源:forms.py

示例10: save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
    def save(self):
        forum = Forum(title=self.title.data,
                      description=self.description.data,
                      position=self.position.data)

        if self.is_category.data:
            forum.is_category = True
        else:
            forum.parent_id = self.parent.data.id

        return forum.save()
开发者ID:RJacksonm1,项目名称:flaskbb,代码行数:13,代码来源:forms.py

示例11: create_welcome_forum

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def create_welcome_forum():
    """
    This will create the `welcome forum` that nearly every
    forum software has after the installation process is finished
    """
    if User.query.count() < 1:
        raise "You need to create the admin user first!"

    user = User.query.filter_by(id=1).first()

    category = Category(title="My Category", position=1)
    category.save()

    forum = Forum(title="Welcome", description="Your first forum",
                  category_id=category.id)
    forum.save()

    topic = Topic(title="Welcome!")
    post = Post(content="Have fun with your new FlaskBB Forum!")

    topic.save(user=user, forum=forum, post=post)
开发者ID:centime,项目名称:xss-paper,代码行数:23,代码来源:populate.py

示例12: create_welcome_forum

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def create_welcome_forum():
    """This will create the `welcome forum` with a welcome topic.
    Returns True if it's created successfully.
    """
    if User.query.count() < 1:
        return False

    user = User.query.filter_by(id=1).first()

    category = Category(title="My Category", position=1)
    category.save()

    forum = Forum(title="Welcome", description="Your first forum",
                  category_id=category.id)
    forum.save()

    topic = Topic(title="Welcome!")
    post = Post(content="Have fun with your new FlaskBB Forum!")

    topic.save(user=user, forum=forum, post=post)
    return True
开发者ID:djsilcock,项目名称:flaskbb,代码行数:23,代码来源:populate.py

示例13: save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
    def save(self):
        forum = Forum(title=self.title.data,
                      description=self.description.data,
                      position=self.position.data)

        if self.moderators.data and not self.is_category.data:
            forum.moderators = self.moderators.data

        if self.is_category.data:
            forum.is_category = True
            forum.parent_id = None
        else:
            forum.parent_id = self.parent.data.id

        return forum.save()
开发者ID:ulysseswolf,项目名称:flaskbb,代码行数:17,代码来源:forms.py

示例14: save

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
    def save(self):
        forum = Forum(title=self.title.data,
                      description=self.description.data,
                      position=self.position.data,
                      external=self.external.data,
                      show_moderators=self.show_moderators.data,
                      locked=self.locked.data)

        if self.moderators.data:
            # is already validated
            forum.moderators = self.moderators.data

        forum.category_id = self.category.data.id

        return forum.save()
开发者ID:delida,项目名称:flaskbb,代码行数:17,代码来源:forms.py

示例15: create_test_data

# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import save [as 别名]
def create_test_data():

    create_default_groups()

    # create 5 users
    for u in range(1, 6):
        username = "test%s" % u
        email = "test%[email protected]" % u
        user = User(username=username, password="test", email=email)
        user.primary_group_id = u
        user.save()

    # create a category
    category = Forum(is_category=True, title="Test Category",
                     description="Test Description")
    category.save()

    # create 2 forums in the category
    for i in range(1, 3):
        forum_title = "Test Forum %s " % i
        forum = Forum(title=forum_title, description="Test Description",
                      parent_id=category.id)
        forum.save()

        # Create a subforum
        subforum_title = "Test Subforum %s " % i
        subforum = Forum(title=subforum_title,
                         description="Test Description", parent_id=forum.id)
        subforum.save()

    user = User.query.filter_by(id=1).first()

    # create 1 topic in each forum
    for i in range(2, 6):  # Forum ids are not sequential because categories.
        forum = Forum.query.filter_by(id=i).first()

        topic = Topic()
        post = Post()

        topic.title = "Test Title %s" % (i-1)
        post.content = "Test Content"
        topic.save(user=user, forum=forum, post=post)
开发者ID:ulysseswolf,项目名称:flaskbb,代码行数:44,代码来源:populate.py


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