def POST_spendcreddits(self, form, jquery, months, passthrough): if months is None or months < 1: form.set_html(".status", _("nice try.")) return days = months * 31 if not passthrough: raise ValueError("/spendcreddits got no passthrough?") blob_key, payment_blob = get_blob(passthrough) if payment_blob["goldtype"] not in ("gift", "code"): raise ValueError("/spendcreddits payment_blob %s has goldtype %s" % (passthrough, payment_blob["goldtype"])) if payment_blob["account_id"] != c.user._id: fmt = ("/spendcreddits payment_blob %s has userid %d " + "but c.user._id is %d") raise ValueError(fmt % passthrough, payment_blob["account_id"], c.user._id) if payment_blob["goldtype"] == "gift": signed = payment_blob["signed"] giftmessage = _force_unicode(payment_blob["giftmessage"]) recipient_name = payment_blob["recipient"] try: recipient = Account._by_name(recipient_name) except NotFound: raise ValueError("Invalid username %s in spendcreddits, buyer = %s" % (recipient_name, c.user.name)) if recipient._deleted: form.set_html(".status", _("that user has deleted their account")) return if not c.user.employee: if months > c.user.gold_creddits: raise ValueError("%s is trying to sneak around the creddit check" % c.user.name) c.user.gold_creddits -= months c.user.gold_creddit_escrow += months c.user._commit() if payment_blob["goldtype"] == "gift": thing_fullname = payment_blob.get("thing") thing = send_gift(c.user, recipient, months, days, signed, giftmessage, thing_fullname) form.set_html(".status", _("the gold has been delivered!")) else: try: send_gold_code(c.user, months, days) except MessageError: form.set_html(".status", _("there was an error creating a gift code. " "please try again later, or contact %(email)s " "for assistance.") % {'email': g.goldthanks_email}) return thing = None form.set_html(".status", _("the gift code has been messaged to you!")) if not c.user.employee: c.user.gold_creddit_escrow -= months c.user._commit() form.find("button").hide() payment_blob["status"] = "processed" g.hardcache.set(blob_key, payment_blob, 86400 * 30) if thing: gilding_message = make_gold_message(thing, user_gilded=True) jquery.gild_thing(thing_fullname, gilding_message, thing.gildings)