from aspen import Response from gittip import db, AMOUNTS from gittip.elsewhere import github from aspen.utils import to_age def _extract_avatar(participant_id): # XXX This can be replaced with Participant.get_img_src when we convert # this simplate to use the ORM. # https://github.com/zetaweb/www.gittip.com/issues/541 out = '/assets/-/avatar-default.gif' recs = db.fetchall(""" SELECT user_info FROM elsewhere WHERE participant_id=%s ORDER BY platform """, (participant_id,)) try: rec = recs.next() except StopIteration: return out # XXX We need to take orphan accounts out of queries in the # caller. See: # https://github.com/zetaweb/www.gittip.com/issues/650 #raise Exception("%s has no elsewheres?" % participant_id) user_info = rec.get('user_info', {}) if 'profile_image_url_https' in user_info: # XXX Attack vector? Can someone inject this value? Don't think so, # but ... out = user_info['profile_image_url_https'] elif 'avatar_url' in user_info: out = user_info['avatar_url'] return 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 = db.fetchall(""" SELECT id, claimed_time FROM ( SELECT DISTINCT ON (p.id) p.id , claimed_time FROM participants p JOIN elsewhere e ON p.id = participant_id 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 = db.fetchall(""" SELECT tipper, anonymous, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tipper FROM tips JOIN participants p ON p.id = tipper JOIN participants p2 ON p2.id = tippee JOIN elsewhere ON elsewhere.participant_id = 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.id = 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/zetaweb/www.gittip.com/issues/650 receivers = db.fetchall(""" SELECT tippee, claimed_time, sum(amount) AS amount FROM ( SELECT DISTINCT ON (tipper, tippee) amount , tippee FROM tips JOIN participants p ON p.id = tipper JOIN elsewhere ON elsewhere.participant_id = 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.id = 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 %}