本文整理汇总了Python中flaskbb.forum.models.Forum类的典型用法代码示例。如果您正苦于以下问题:Python Forum类的具体用法?Python Forum怎么用?Python Forum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Forum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
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()
示例2: save
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()
示例3: get
def get(self, forum_id, slug=None):
forum_instance, forumsread = Forum.get_forum(
forum_id=forum_id, user=real(current_user)
)
if forum_instance.external:
return redirect(forum_instance.external)
# remove the current forum from the select field (move).
available_forums = Forum.query.order_by(Forum.position).all()
available_forums.remove(forum_instance)
page = request.args.get("page", 1, type=int)
topics = Forum.get_topics(
forum_id=forum_instance.id,
user=real(current_user),
page=page,
per_page=flaskbb_config["TOPICS_PER_PAGE"]
)
return render_template(
"forum/edit_forum.html",
forum=forum_instance,
topics=topics,
available_forums=available_forums,
forumsread=forumsread,
)
示例4: test_forum_save
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]
示例5: view_forum
def view_forum(forum_id, slug=None):
page = request.args.get('page', 1, type=int)
forum, forumsread = Forum.get_forum(forum_id=forum_id, user=current_user)
topics = Forum.get_topics(forum_id=forum.id, user=current_user, page=page,
per_page=current_app.config["TOPICS_PER_PAGE"])
return render_template("forum/forum.html", forum=forum, topics=topics,
forumsread=forumsread,)
示例6: save
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()
示例7: test_topic_merge_other_forum
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)
示例8: test_forum_save
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
示例9: save
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()
示例10: save
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()
示例11: test_topic_move
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
示例12: create_test_data
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)
示例13: test_forum_get_topics
def test_forum_get_topics(topic, user):
forum = topic.forum
with current_app.test_request_context():
# Test with logged in user
login_user(user)
topics = Forum.get_topics(forum_id=forum.id, user=current_user)
assert topics.items == [(topic, None)]
# Test with logged out user
logout_user()
topics = Forum.get_topics(forum_id=forum.id, user=current_user)
assert topics.items == [(topic, None)]
示例14: test_forum_get_forum
def test_forum_get_forum(forum, user):
with current_app.test_request_context():
# Test with logged in user
login_user(user)
forum_with_forumsread = \
Forum.get_forum(forum_id=forum.id, user=current_user)
assert forum_with_forumsread == (forum, None)
# Test with logged out user
logout_user()
forum_with_forumsread = \
Forum.get_forum(forum_id=forum.id, user=current_user)
assert forum_with_forumsread == (forum, None)
示例15: test_topic_move
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