def top_ten(request): week = request.GET.get('week') if week: try: week = datetime.strptime(week, '%m-%d-%Y') except: return JsonResponse({'status': 'ILLEGAL_DATE_FORMAT'}) from models import UserStats top10_stats = UserStats.get_weekly_top_10(week) top10 = [] for s in top10_stats: all_time_stats = UserStats.get_all_time_stats(s.user) prestige, challenge_progress = divmod(all_time_stats.get('all_time_steps'), 100) top10.append({'name': s.user.public_name, 'id': s.user.pk, 'prestige': prestige, 'total_steps': s.total_steps() }) return JsonResponse({'status': 'OK', 'top_10': top10, })