mirror of
https://github.com/kennethreitz-archive/www.gittip.com.git
synced 2026-06-21 15:50:59 +00:00
0c9e0b8886
Fixing issue 163 (commas in goal funding field)
34 lines
802 B
JSON
34 lines
802 B
JSON
import locale
|
|
import decimal
|
|
|
|
from aspen import Response
|
|
from gittip import db
|
|
|
|
# ========================================================================== ^L
|
|
|
|
if user.ANON:
|
|
raise Response(404)
|
|
request.allow("POST")
|
|
|
|
goal = request.body["goal"]
|
|
|
|
if goal == "null":
|
|
goal = None
|
|
elif goal == "custom":
|
|
goal = request.body["goal_custom"].replace(',', '')
|
|
|
|
if goal is not None:
|
|
try:
|
|
goal = decimal.Decimal(goal)
|
|
except decimal.InvalidOperation:
|
|
raise Response(400, "Bad input.")
|
|
|
|
rec = db.fetchone( "UPDATE participants SET goal=%s "
|
|
"WHERE id=%s RETURNING goal"
|
|
, (goal, user.id)
|
|
)
|
|
goal = rec['goal']
|
|
if goal is not None:
|
|
goal = locale.format("%.2f", rec['goal'], grouping=True)
|
|
response.body = {"goal": goal}
|