Files
2013-02-01 10:46:19 -05:00

63 lines
1.5 KiB
JSON

"""JSON endpoint for a Gittip widget.
"""
from gittip.models import Participant
# ========================================================================== ^L
participant = Participant.query.get(path['participant_id'])
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.id == path['participant_id']:
my_tip = "self"
else:
my_tip = user.get_tip_to(path['participant_id'])
output["my_tip"] = str(my_tip)
response.headers["Access-Control-Allow-Origin"] = "*"
response.body = output