from aspen import Response from aspen.utils import to_age from gittip import db, AMOUNTS from gittip.elsewhere import github from gittip.models.participant import Participant def _wrap(raw): """This is a step on the way to ORM-ifying this simplate. """ for rec in raw: out = Participant.query.get(rec['username']) if 'amount' in rec: out.amount = rec['amount'] yield out def _to_age(participant): # XXX I can't believe I'm doing this. Evolve aspen.utils.to_age! age = to_age(participant.claimed_time, fmt_past="%(age)s") age = age.replace('just a moment', 'just now') age = age.replace('an ', '1 ').replace('a ', '1 ') words = ('zero', 'one', 'two','three', 'four', 'five', 'six', 'seven', 'eight', 'nine') for i, word in enumerate(words): age = age.replace(word, str(i)) return age.replace(' ', ' ') + "" ^L try: limit = min(int(qs.get('limit', 10)), 100) offset = int(qs.get('offset', 0)) except ValueError: raise Response(400) new_participants = _wrap(db.fetchall(""" SELECT username, claimed_time FROM ( SELECT DISTINCT ON (p.username) p.username , claimed_time FROM participants p JOIN elsewhere e ON p.username = participant WHERE claimed_time IS NOT null AND is_suspicious IS NOT true ) AS foo ORDER BY claimed_time DESC LIMIT %s OFFSET %s """, (limit, offset))) givers = _wrap(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 = _wrap(db.fetchall(""" SELECT tippee AS username, claimed_time, 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))) ^L {% extends templates/base.html %} {% block head %} {% end %} {% block heading %}