@render_to('race/awards.html')
def awards(request):
	if request.user.is_authenticated():
		user_badges = set((slug, level) for slug, level in
			BadgeAward.objects.filter(
				user = request.user
			).values_list("slug", "level"))
	else:
		user_badges = []

	badges_awarded = BadgeAward.objects.values("slug", "level").annotate(
		num = Count("pk")
	)

	badges_counts = {"{0}_{1}".format(k['slug'], k['level']): k['num'] for k in badges_awarded}

	user_count = UserProfile.objects.count()

	badges_list = list()
	for badge_cls in badges._registry.values():
		for level, badge in enumerate(badge_cls.levels):
			badge_count = badges_counts.get("{0}_{1}".format(badge_cls.slug, level), 0)
			badges_list.append({
				"slug": badge_cls.slug,
				"level": level,
				"name": badge.name,
				"description": badge.description,
				"count": badge_count,
				"percentage": badge_count/float(user_count) * 100 if user_count else 0,
				"user_has": (badge_cls.slug, level) in user_badges,
			})

	return {
		'badges_list': badges_list,
		'user_count': user_count,
	}
dataset/ETHPy150Open chaosk/teerace/teerace/race/views.py/awards/original