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

87 lines
2.4 KiB
JSON

"""JSON endpoint for a Gittip widget.
"""
from gittip.models import Participant
# ========================================================================== ^L
participant = Participant.query.get(path['username'])
receiving = participant.get_dollars_receiving()
output = {"receiving": str(receiving)}
# Generate goal key
# =================
# Display values:
#
# undefined - user is not here to receive tips, but will generally regift them
# null - user has no funding goal
# 3.00 - user wishes to receive at least this amount
if participant.goal != 0:
if participant.goal > 0:
goal = str(participant.goal)
else:
goal = None
output["goal"] = goal
# Generate giving key
# ===================
# Display values:
#
# null - user is giving anonymously
# 3.00 - user gives this amount in tips
if not participant.anonymous:
giving = str(participant.get_dollars_giving())
else:
giving = None
output["giving"] = giving
# Generate my_tip key
# ===================
# Display values:
#
# undefined - user is not authenticated
# "self" - user == participant
# null - user has never tipped this person
# 0.00 - user used to tip this person but now doesn't
# 3.00 - user tips this person this amount
if not user.ANON:
if user.username == path['username']:
my_tip = "self"
else:
my_tip = user.get_tip_to(path['username'])
output["my_tip"] = str(my_tip)
# Accounts Elsewhere
# ==================
# For Twitter we can use an immutable id. For GitHub we have an immutable id
# but we can't use it. For Bitbucket we don't have an immutable id. It's nice
# that Twitter lets us use an immutable id. We should do that ourselves:
#
# https://github.com/gittip/www.gittip.com/issues/680
github, twitter, bitbucket = participant.get_accounts_elsewhere()
if bitbucket is not None:
bitbucket = "https://bitbucket.org/api/1.0/users/%s" % \
bitbucket.user_info['username']
if github is not None:
github = "https://api.github.com/users/%s" % github.user_info['login']
if twitter is not None:
twitter = "https://api.twitter.com/1/users/show.json?id=%s" \
"&include_entities=1" % twitter.user_id
output['elsewhere'] = { 'bitbucket': bitbucket
, 'github': github
, 'twitter': twitter
}
response.headers["Access-Control-Allow-Origin"] = "*"
response.body = output