def order_post(request): code = request.POST.get('code') if code: return order_post_gc(request, code) times = (1, 3, 6, 12) try: method_name = request.POST.get('method') time_months = int(request.POST.get('time')) except ValueError: return HTTPBadRequest('invalid POST data') if method_name not in methods.METHODS or time_months not in times: return HTTPBadRequest('Invalid method/time') time = datetime.timedelta(days=30 * time_months) o = Order(user=request.user, time=time, amount=0, method=0) o.close_date = datetime.datetime.now() + datetime.timedelta(days=7) o.paid = False o.payment = {} method = methods.METHODS[method_name]() method.init(request, o) DBSession.add(o) DBSession.flush() return method.start(request, o)