Mercurial > public > sg101
changeset 349:a43add8af83d
Fix #171; forums weren't assigning badge ownership correctly when pre-fetching data.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 02 Mar 2011 02:34:57 +0000 |
parents | d1b11096595b |
children | 2177a71b680c |
files | gpp/forums/views/main.py |
diffstat | 1 files changed, 4 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/gpp/forums/views/main.py Wed Mar 02 02:18:28 2011 +0000 +++ b/gpp/forums/views/main.py Wed Mar 02 02:34:57 2011 +0000 @@ -181,6 +181,7 @@ users = set(post.user.id for post in page.object_list) profiles = UserProfile.objects.filter(user__id__in=users).select_related() + profile_keys = [profile.id for profile in profiles] user_profiles = dict((profile.user.id, profile) for profile in profiles) for post in page.object_list: @@ -190,13 +191,13 @@ # Attach badge ownership info to the user profiles to avoid lots # of database hits in the template: bos_qs = BadgeOwnership.objects.filter( - profile__id__in=user_profiles.keys()).select_related() + profile__id__in=profile_keys).select_related() bos = collections.defaultdict(list) for bo in bos_qs: bos[bo.profile.id].append(bo) - for pk, profile in user_profiles.iteritems(): - profile.badge_ownership = bos[pk] + for user_id, profile in user_profiles.iteritems(): + profile.badge_ownership = bos[profile.id] # Attach any attachments post_ids = [post.pk for post in page.object_list]