-def badge(request, id):
- badge = get_object_or_404(Badge, id=id)
- awards = Award.objects.extra(
- select={'id': 'auth_user.id',
- 'name': 'auth_user.username',
- 'rep':'forum_user.reputation',
- 'gold': 'forum_user.gold',
- 'silver': 'forum_user.silver',
- 'bronze': 'forum_user.bronze'},
- tables=['award', 'auth_user', 'forum_user'],
- where=['badge_id=%s AND user_id=auth_user.id AND forum_user.user_ptr_id = auth_user.id'],
- params=[id]
- ).distinct('id')
+def badge(request, id, slug):
+ badge = Badge.objects.get(id=id)
+ awards = list(Award.objects.filter(badge=badge).order_by('user', 'awarded_at'))
+ award_count = len(awards)
+
+ awards = sorted([dict(count=len(list(g)), user=k) for k, g in groupby(awards, lambda a: a.user)],
+ lambda c1, c2: c2['count'] - c1['count'])