mirror of
https://github.com/kennethreitz-archive/www.gittip.com.git
synced 2026-06-21 15:50:59 +00:00
40 lines
958 B
JSON
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.id
|
|
tippee = path['participant_id']
|
|
|
|
|
|
# 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
|