export_ranking now exports KyuDanRankings and SeasonRankings.
This commit is contained in:
@@ -157,3 +157,37 @@ class SeasonRankingManager(models.Manager):
|
||||
'won_hanchans': user['won_hanchans']
|
||||
})
|
||||
return json_data
|
||||
|
||||
class KyuDanRankingManager(models.Manager):
|
||||
|
||||
def json_data(self):
|
||||
""" Get all Rankings for a given Season and return them as a list of
|
||||
dict objects, suitable for JSON exports and other processings.
|
||||
|
||||
:param season: Season that should be exported, current season if empty
|
||||
:return: a list() of dict() objects suiteable for JSON export.
|
||||
"""
|
||||
json_data = list()
|
||||
values = self.all()
|
||||
values = values.values('user_id', 'user__username',
|
||||
'user__first_name', 'user__last_name',
|
||||
'dan', 'dan_points', 'kyu', 'kyu_points',
|
||||
'hanchan_count', 'won_hanchans', 'good_hanchans')
|
||||
for user in values:
|
||||
if user['dan']:
|
||||
rank = '{}. Dan'.format(user['dan'])
|
||||
points = user['dan_points']
|
||||
else:
|
||||
rank = '{}. Kyū'.format(user['kyu'])
|
||||
points = user['kyu_points']
|
||||
json_data.append({
|
||||
'user_id': user['user_id'],
|
||||
'username': user['user__username'],
|
||||
'full_name': " ".join([user['user__last_name'], user['user__first_name']]),
|
||||
'rank': rank,
|
||||
'points': points,
|
||||
'hanchan_count': user['hanchan_count'],
|
||||
'good_hanchans': user['good_hanchans'],
|
||||
'won_hanchans': user['won_hanchans']
|
||||
})
|
||||
return json_data
|
||||
|
||||
Reference in New Issue
Block a user