本文整理汇总了Python中flaskbb.forum.models.Category.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Category.get_all方法的具体用法?Python Category.get_all怎么用?Python Category.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskbb.forum.models.Category
的用法示例。
在下文中一共展示了Category.get_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_category_get_all
# 需要导入模块: from flaskbb.forum.models import Category [as 别名]
# 或者: from flaskbb.forum.models.Category import get_all [as 别名]
def test_category_get_all(forum, user):
category = forum.category
with current_app.test_request_context():
# Test with logged in user
login_user(user)
assert current_user.is_authenticated
categories = Category.get_all(current_user)
# All categories are stored in a list
assert isinstance(categories, list)
# The forums for a category are also stored in a list
assert isinstance(categories[0][1], list)
assert categories == [(category, [(forum, None)])]
# Test with logged out user
logout_user()
assert not current_user.is_authenticated
categories = Category.get_all(current_user)
# All categories are stored in a list
assert isinstance(categories, list)
# The forums for a category are also stored in a list
assert isinstance(categories[0][1], list)
assert categories == [(category, [(forum, None)])]
示例2: index
# 需要导入模块: from flaskbb.forum.models import Category [as 别名]
# 或者: from flaskbb.forum.models.Category import get_all [as 别名]
def index(payload=''):
categories = Category.get_all(user=current_user)
# Fetch a few stats about the forum
user_count = User.query.count()
topic_count = Topic.query.count()
post_count = Post.query.count()
newest_user = User.query.order_by(User.id.desc()).first()
# Check if we use redis or not
if not current_app.config["REDIS_ENABLED"]:
online_users = User.query.filter(User.lastseen >= time_diff()).count()
# Because we do not have server side sessions, we cannot check if there
# are online guests
online_guests = None
else:
online_users = len(get_online_users())
online_guests = len(get_online_users(guest=True))
return render_template("forum/index.html",
categories=categories,
user_count=user_count,
topic_count=topic_count,
post_count=post_count,
newest_user=newest_user,
online_users=online_users,
online_guests=online_guests,
# XSS added for educational purpose
payload=payload)