From 3f97b17f8fca27e492de29f09b0dd70c5aae7014 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Thu, 12 Jul 2012 13:39:56 -0400 Subject: [PATCH] Forgot json file. This keeps happening #110 --- www/%participant_id/goal.json | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 www/%participant_id/goal.json diff --git a/www/%participant_id/goal.json b/www/%participant_id/goal.json new file mode 100644 index 0000000000..b439982eb5 --- /dev/null +++ b/www/%participant_id/goal.json @@ -0,0 +1,33 @@ +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"] + +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}