Files
Chad Whitacre 0c9e0b8886 Merge pull request #227 from atroche/master
Fixing issue 163 (commas in goal funding field)
2012-08-16 14:03:37 -07:00

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}