本文整理汇总了Python中flaskbb.forum.models.Forum.get_forum方法的典型用法代码示例。如果您正苦于以下问题:Python Forum.get_forum方法的具体用法?Python Forum.get_forum怎么用?Python Forum.get_forum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskbb.forum.models.Forum
的用法示例。
在下文中一共展示了Forum.get_forum方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import get_forum [as 别名]
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,
)
示例2: test_forum_get_forum
# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import get_forum [as 别名]
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)
示例3: view_forum
# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import get_forum [as 别名]
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,)
示例4: view_forum
# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import get_forum [as 别名]
def view_forum(forum_id, slug=None):
page = request.args.get('page', 1, type=int)
forum_instance, forumsread = Forum.get_forum(forum_id=forum_id,
user=current_user)
if forum_instance.external:
return redirect(forum_instance.external)
topics = Forum.get_topics(
forum_id=forum_instance.id, user=current_user, page=page,
per_page=flaskbb_config["TOPICS_PER_PAGE"]
)
return render_template(
"forum/forum.html", forum=forum_instance,
topics=topics, forumsread=forumsread,
)
示例5: manage_forum
# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import get_forum [as 别名]
def manage_forum(forum_id, slug=None):
page = request.args.get('page', 1, type=int)
forum_instance, forumsread = Forum.get_forum(forum_id=forum_id,
user=current_user)
# remove the current forum from the select field (move).
available_forums = Forum.query.order_by(Forum.position).all()
available_forums.remove(forum_instance)
if not Permission(IsAtleastModeratorInForum(forum=forum_instance)):
flash(_("You do not have the permissions to moderate this forum."),
"danger")
return redirect(forum_instance.url)
if forum_instance.external:
return redirect(forum_instance.external)
topics = Forum.get_topics(
forum_id=forum_instance.id, user=current_user, page=page,
per_page=flaskbb_config["TOPICS_PER_PAGE"]
)
mod_forum_url = url_for("forum.manage_forum", forum_id=forum_instance.id,
slug=forum_instance.slug)
# the code is kind of the same here but it somehow still looks cleaner than
# doin some magic
if request.method == "POST":
ids = request.form.getlist("rowid")
tmp_topics = Topic.query.filter(Topic.id.in_(ids)).all()
# locking/unlocking
if "lock" in request.form:
changed = do_topic_action(topics=tmp_topics, user=current_user,
action="locked", reverse=False)
flash(_("%(count)s Topics locked.", count=changed), "success")
return redirect(mod_forum_url)
elif "unlock" in request.form:
changed = do_topic_action(topics=tmp_topics, user=current_user,
action="locked", reverse=True)
flash(_("%(count)s Topics unlocked.", count=changed), "success")
return redirect(mod_forum_url)
# highlighting/trivializing
elif "highlight" in request.form:
changed = do_topic_action(topics=tmp_topics, user=current_user,
action="important", reverse=False)
flash(_("%(count)s Topics highlighted.", count=changed), "success")
return redirect(mod_forum_url)
elif "trivialize" in request.form:
changed = do_topic_action(topics=tmp_topics, user=current_user,
action="important", reverse=True)
flash(_("%(count)s Topics trivialized.", count=changed), "success")
return redirect(mod_forum_url)
# deleting
elif "delete" in request.form:
changed = do_topic_action(topics=tmp_topics, user=current_user,
action="delete", reverse=False)
flash(_("%(count)s Topics deleted.", count=changed), "success")
return redirect(mod_forum_url)
# moving
elif "move" in request.form:
new_forum_id = request.form.get("forum")
if not new_forum_id:
flash(_("Please choose a new forum for the topics."), "info")
return redirect(mod_forum_url)
new_forum = Forum.query.filter_by(id=new_forum_id).first_or_404()
# check the permission in the current forum and in the new forum
if not Permission(
And(
IsAtleastModeratorInForum(forum_id=new_forum_id),
IsAtleastModeratorInForum(forum=forum_instance)
)
):
flash(_("You do not have the permissions to move this topic."),
"danger")
return redirect(mod_forum_url)
new_forum.move_topics_to(tmp_topics)
return redirect(mod_forum_url)
return render_template(
"forum/edit_forum.html", forum=forum_instance, topics=topics,
available_forums=available_forums, forumsread=forumsread,
)
示例6: post
# 需要导入模块: from flaskbb.forum.models import Forum [as 别名]
# 或者: from flaskbb.forum.models.Forum import get_forum [as 别名]
def post(self, forum_id, slug=None): # noqa: C901
forum_instance, __ = Forum.get_forum(
forum_id=forum_id, user=real(current_user)
)
mod_forum_url = url_for(
"forum.manage_forum",
forum_id=forum_instance.id,
slug=forum_instance.slug
)
ids = request.form.getlist("rowid")
tmp_topics = Topic.query.filter(Topic.id.in_(ids)).all()
if not len(tmp_topics) > 0:
flash(
_(
"In order to perform this action you have to select at "
"least one topic."
), "danger"
)
return redirect(mod_forum_url)
# locking/unlocking
if "lock" in request.form:
changed = do_topic_action(
topics=tmp_topics,
user=real(current_user),
action="locked",
reverse=False
)
flash(_("%(count)s topics locked.", count=changed), "success")
return redirect(mod_forum_url)
elif "unlock" in request.form:
changed = do_topic_action(
topics=tmp_topics,
user=real(current_user),
action="locked",
reverse=True
)
flash(_("%(count)s topics unlocked.", count=changed), "success")
return redirect(mod_forum_url)
# highlighting/trivializing
elif "highlight" in request.form:
changed = do_topic_action(
topics=tmp_topics,
user=real(current_user),
action="important",
reverse=False
)
flash(_("%(count)s topics highlighted.", count=changed), "success")
return redirect(mod_forum_url)
elif "trivialize" in request.form:
changed = do_topic_action(
topics=tmp_topics,
user=real(current_user),
action="important",
reverse=True
)
flash(_("%(count)s topics trivialized.", count=changed), "success")
return redirect(mod_forum_url)
# deleting
elif "delete" in request.form:
changed = do_topic_action(
topics=tmp_topics,
user=real(current_user),
action="delete",
reverse=False
)
flash(_("%(count)s topics deleted.", count=changed), "success")
return redirect(mod_forum_url)
# moving
elif "move" in request.form:
new_forum_id = request.form.get("forum")
if not new_forum_id:
flash(_("Please choose a new forum for the topics."), "info")
return redirect(mod_forum_url)
new_forum = Forum.query.filter_by(id=new_forum_id).first_or_404()
# check the permission in the current forum and in the new forum
if not Permission(
And(IsAtleastModeratorInForum(forum_id=new_forum_id),
IsAtleastModeratorInForum(forum=forum_instance))):
flash(
_("You do not have the permissions to move this topic."),
"danger"
)
return redirect(mod_forum_url)
if new_forum.move_topics_to(tmp_topics):
flash(_("Topics moved."), "success")
else:
flash(_("Failed to move topics."), "danger")
#.........这里部分代码省略.........