# HG changeset patch # User Brian Neal # Date 1299033297 0 # Node ID a43add8af83d04465b0d25e0033ed1ef81f44cf0 # Parent d1b11096595bb018c7a704f88746627cdaa49b20 Fix #171; forums weren't assigning badge ownership correctly when pre-fetching data. diff -r d1b11096595b -r a43add8af83d gpp/forums/views/main.py --- 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]