Skip to content

Commit

Permalink
Merge pull request #168 from ractf/hotfix/ctftime-unannounced-api-update
Browse files Browse the repository at this point in the history
Add incrementing position field for CTFtime view
  • Loading branch information
david-cooke authored Aug 9, 2021
2 parents 423b6e6 + f1c1adb commit 86da7d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/leaderboard/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@


class CTFTimeSerializer(serializers.BaseSerializer):
position: int = 0

def to_representation(self, instance):
return {"team": instance.name, "score": instance.leaderboard_points}
# TODO: Use SerializerFields for team, score and position.
return {"team": instance.name, "score": instance.leaderboard_points, "pos": self.get_position(instance)}

def get_position(self, _) -> int:
"""Return an incrementing field representing leaderboard positions."""
self.position += 1
return self.position


class LeaderboardTeamScoreSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit 86da7d9

Please sign in to comment.