本文整理汇总了Python中flaskbb.forum.models.ForumsRead.forum方法的典型用法代码示例。如果您正苦于以下问题:Python ForumsRead.forum方法的具体用法?Python ForumsRead.forum怎么用?Python ForumsRead.forum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskbb.forum.models.ForumsRead
的用法示例。
在下文中一共展示了ForumsRead.forum方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from flaskbb.forum.models import ForumsRead [as 别名]
# 或者: from flaskbb.forum.models.ForumsRead import forum [as 别名]
def post(self, forum_id=None, slug=None):
# Mark a single forum as read
if forum_id is not None:
forum_instance = Forum.query.filter_by(id=forum_id).first_or_404()
forumsread = ForumsRead.query.filter_by(
user_id=real(current_user).id, forum_id=forum_instance.id
).first()
TopicsRead.query.filter_by(
user_id=real(current_user).id, forum_id=forum_instance.id
).delete()
if not forumsread:
forumsread = ForumsRead()
forumsread.user = real(current_user)
forumsread.forum = forum_instance
forumsread.last_read = time_utcnow()
forumsread.cleared = time_utcnow()
db.session.add(forumsread)
db.session.commit()
flash(
_(
"Forum %(forum)s marked as read.",
forum=forum_instance.title
), "success"
)
return redirect(forum_instance.url)
# Mark all forums as read
ForumsRead.query.filter_by(user_id=real(current_user).id).delete()
TopicsRead.query.filter_by(user_id=real(current_user).id).delete()
forums = Forum.query.all()
forumsread_list = []
for forum_instance in forums:
forumsread = ForumsRead()
forumsread.user = real(current_user)
forumsread.forum = forum_instance
forumsread.last_read = time_utcnow()
forumsread.cleared = time_utcnow()
forumsread_list.append(forumsread)
db.session.add_all(forumsread_list)
db.session.commit()
flash(_("All forums marked as read."), "success")
return redirect(url_for("forum.index"))