fix getting group query on topic page
This commit is contained in:
parent
cc4a038a27
commit
cecd11eb9c
1 changed files with 2 additions and 28 deletions
|
@ -401,7 +401,7 @@ def show_topic(request, topic_id, full=True):
|
|||
# without specifying, following query wouldn't select related properly
|
||||
posts = topic.posts.select_related('user__userprofile',
|
||||
'user__forum_profile',
|
||||
'updated_by', 'user__groups', 'user').all()
|
||||
'updated_by', 'user').prefetch_related('user__groups').all()
|
||||
edit_start = timezone.now() - timedelta(minutes=1)
|
||||
edit_end = timezone.now()
|
||||
editable = posts.filter(created__range=(edit_start, edit_end)).filter(user_id=request.user.id)
|
||||
|
@ -449,32 +449,6 @@ def show_topic(request, topic_id, full=True):
|
|||
**post_form_kwargs
|
||||
)
|
||||
|
||||
def get_user_groups(user_ids):
|
||||
"""
|
||||
"""
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
select
|
||||
user_id,
|
||||
group_concat(auth_group.name)
|
||||
from
|
||||
auth_user_groups
|
||||
join auth_group on
|
||||
auth_user_groups.group_id=auth_group.id
|
||||
where
|
||||
user_id in %s
|
||||
group by
|
||||
user_id;
|
||||
""", [user_ids])
|
||||
rows = cursor.fetchall()
|
||||
lookup = {}
|
||||
for user_id, groups in rows:
|
||||
lookup[user_id] = groups.split(',')
|
||||
return lookup
|
||||
|
||||
user_ids = [post.user.id for post in posts]
|
||||
user_groups = get_user_groups(user_ids)
|
||||
|
||||
group_titles = {}
|
||||
|
||||
for post in posts:
|
||||
|
@ -483,7 +457,7 @@ def show_topic(request, topic_id, full=True):
|
|||
group_titles[post.user] = "Scratch Team"
|
||||
|
||||
else:
|
||||
temp_names = user_groups[post.user.id]
|
||||
temp_names = [group.name for group in post.user.groups.all()]
|
||||
if "Forum Moderators" in temp_names:
|
||||
group_titles[post.user] = "Forum Moderator"
|
||||
elif "Scratchers" in temp_names:
|
||||
|
|
Reference in a new issue