def post(self): email = get_user_email() if not email: self.redirect(users.create_login_url('/account')) # query ndb to get the current user beerUser = BeerUser.get_user_profile(email) cart = beerUser.cart.contents address = self.request.get("addressTxt") beers_in_cart = [] if not address: render_template(self, "ordercomplete.html", {"msg":"Invalid delivery address!"}) return if len(cart) != 0: order_string = "" totalcost=0 # Build the order object and save it to the ndb new_order = BeerOrder() for beer in cart: ndb_beer = Beer.query(Beer.beerid == int(beer)).fetch(1)[0] totalcost += int(cart[beer]) * float(ndb_beer.price) quantity = cart[str(ndb_beer.beerid)] if quantity > 0: order_string += "{!s}x {!s}\n".format(quantity,ndb_beer.product) if totalcost > beerUser.balance: render_template(self, "ordercomplete.html", {"msg":"Insufficient funds."}) return new_order.items = order_string new_order.priceSum = totalcost new_order.address = address new_order.status = "Verifying" new_order.orderedBy = email new_order.put() # save the address for the user beerUser.address = address beerUser.balance = beerUser.balance - new_order.priceSum #clear their shopping cart beerUser.cart = ShoppingCart() beerUser.cart.price = "0.00" beerUser.cart.contents = {} beerUser.put() mail.send_mail('*****@*****.**', email, 'Order Verifying', 'You have successfully placed a beer order! Your order will be verified shortly and completed! Thanks!') render_template(self, "ordercomplete.html", {"msg":"Your order has been placed."}) else: render_template(self, "ordercomplete.html",{"msg":"Shopping cart is empty."})
def post(self): email = get_user_email() if email and is_user_admin(): # get params from post request data = json.loads(self.request.body) order = BeerOrder() order.items = data["items"] order.priceSum = float(data["priceSum"]) order.address = data["address"] order.status = "Verifying" order.orderedBy = data["orderedBy"] order.put() else: self.redirect('/home')