Commit 7e439402 by Zia Fazal Committed by Jonathan Piacenti

ziafazal/api-fix-for-proficiency-position-bug

fixed proficiency position bug

exclude the student whose position is being retrieved
parent f351c442
......@@ -26,7 +26,14 @@ class CourseLeadersSerializer(serializers.Serializer):
username = serializers.CharField(source='student__username')
title = serializers.CharField(source='student__profile__title')
avatar_url = serializers.CharField(source='student__profile__avatar_url')
points_scored = serializers.IntegerField()
points_scored = serializers.SerializerMethodField('get_points_scored')
def get_points_scored(self, obj):
"""
formats points_scored to two decimal points
"""
points_scored = obj['points_scored'] or 0
return round(points_scored, 2)
class CourseCompletionsLeadersSerializer(serializers.Serializer):
......
......@@ -1562,8 +1562,10 @@ class CoursesLeadersList(SecureListAPIView):
user_points = StudentModule.objects.filter(course_id__exact=course_key,
student__id=user_id).aggregate(points=Sum('grade'))
user_points = user_points['points'] or 0
user_points = round(user_points, 2)
users_above = queryset.values('student__id').annotate(points=Sum('grade')).\
filter(points__gt=user_points).count()
filter(points__gt=user_points).exclude(student__id=user_id).count() # excluding user to overcome
# float comparison bug
data['position'] = users_above + 1
data['points'] = user_points
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment