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

40 lines
958 B
JSON

"""Get or change the authenticated user's tip to this person.
"""
from decimal import InvalidOperation
from aspen import Response
# ========================================================================== ^L
out = {}
if not user.ANON:
# Get tipper and tippee.
# ======================
# XXX We could/should enforce that tips cannot be pledged at all to locked
# accounts.
tipper = user.username
tippee = path['username']
# Get and maybe set amount.
# =========================
if tippee == tipper:
amount = None
elif POST and 'amount' in body:
try:
amount = user.set_tip_to(tippee, body['amount'])
except (InvalidOperation, ValueError):
raise Response(400, "bad amount")
else:
amount = user.get_tip_to(tippee)
total_giving = user.get_dollars_giving()
out = {"amount": str(amount), "total_giving": str(total_giving)}
response.body = out