Files
Chad Whitacre 28cb48c72a Big changeover from id to username; #287
I sort of did this one with the blast shield down. I haven't even run
the tests yet. The sorts of things I changed:

 - SQL {elsewhere,exchanges}.participant_id => .participant
 - SQL participants.id => .username
 - ORM {user,participant,self}.id => .username
2013-04-05 15:48:59 -04:00

73 lines
2.2 KiB
JSON

"""This is a horribly WET duplicate of www/index.html.
"""
from gittip import db
^L
try:
limit = min(int(qs.get('limit', 10)), 100)
offset = int(qs.get('offset', 0))
except ValueError:
raise Response(400)
givers = list(db.fetchall("""
SELECT tipper AS username, anonymous, sum(amount) AS amount
FROM ( SELECT DISTINCT ON (tipper, tippee)
amount
, tipper
FROM tips
JOIN participants p ON p.username = tipper
JOIN participants p2 ON p2.username = tippee
JOIN elsewhere ON elsewhere.participant = tippee
WHERE p.last_bill_result = ''
AND p.is_suspicious IS NOT true
AND p2.claimed_time IS NOT NULL
AND elsewhere.is_locked = false
ORDER BY tipper, tippee, mtime DESC
) AS foo
JOIN participants p ON p.username = tipper
WHERE is_suspicious IS NOT true
GROUP BY tipper, anonymous
ORDER BY amount DESC
LIMIT %s
OFFSET %s
""", (limit, offset)))
# XXX I'm nearly positive that one or both of givers and receivers can contain
# orphan accounts. See https://github.com/gittip/www.gittip.com/issues/650
receivers = list(db.fetchall("""
SELECT tippee AS username, sum(amount) AS amount
FROM ( SELECT DISTINCT ON (tipper, tippee)
amount
, tippee
FROM tips
JOIN participants p ON p.username = tipper
JOIN elsewhere ON elsewhere.participant = tippee
WHERE last_bill_result = ''
AND elsewhere.is_locked = false
AND is_suspicious IS NOT true
AND claimed_time IS NOT null
ORDER BY tipper, tippee, mtime DESC
) AS foo
JOIN participants p ON p.username = tippee
WHERE is_suspicious IS NOT true
GROUP BY tippee, claimed_time
ORDER BY amount DESC
LIMIT %s
OFFSET %s
""", (limit, offset)))
# anonymize
for giver in givers:
anon = giver.pop('anonymous')
if anon:
giver['username'] = None
response.body = { "givers": givers
, "receivers": receivers
}