-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.py
42 lines (38 loc) · 1.27 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import urllib
from google.appengine.ext import db
from models import Team
import config_NOCOMMIT
def leaderboardGetter(offset, limit, orderBy):
leaderboard = config_NOCOMMIT.pledge_service.getLeaderboard(
offset=offset, limit=limit, orderBy=orderBy)
def team_iter():
for team_data in leaderboard:
if team_data["total_cents"] == 0:
continue
if team_data["team"].startswith('{{team.key()}}'):
# sentinel value == no team
continue
team = Team.get(db.Key(team_data["team"]))
if team is None:
continue
yield team_data, team
teams = []
for idx, (team_data, team) in enumerate(team_iter()):
teams.append({
"amount": int(team_data["total_cents"] / 100),
"num_pledges":int(team_data["num_pledges"]),
"title": team.title,
"primary_slug": team.primary_slug,
"position": 1 + offset + idx})
prev_link, next_link = None, None
if offset > 0:
prev_link = "?%s" % urllib.urlencode({
"offset": max(offset - limit, 0),
"limit": limit,
"orderBy": orderBy})
if len(teams) == limit:
next_link = "?%s" % urllib.urlencode({
"offset": offset + limit,
"limit": limit,
"orderBy": orderBy})
return teams, prev_link, next_link