def get_forums(query_result, user):
"""Returns a tuple which contains the category and the forums as list.
This is the counterpart for get_categories_and_forums and especially
usefull when you just need the forums for one category.
For example::
(<Category 2>,
[(<Forum 3>, None),
(<Forum 4>, None)])
:param query_result: A tuple (KeyedTuple) with all categories and forums
:param user: The user object is needed because a signed out user does not
have the ForumsRead relation joined.
"""
it = itertools.groupby(query_result, operator.itemgetter(0))
if user.is_authenticated:
for key, value in it:
forums = key, [(item[1], item[2]) for item in value]
else:
for key, value in it:
forums = key, [(item[1], None) for item in value]
return forums
评论列表
文章目录