def get(self): # self.response.write("My Orders") user = users.get_current_user() restaurant_list = RestaurantModel.query(RestaurantModel.owner==user).fetch() OrdersToMe_info = [] for restaurant in restaurant_list: OrderToRestaurant_list = HistoryCartModel.query(HistoryCartModel.restaurant_name==restaurant.name).order(-HistoryCartModel.createTime).fetch() if (len(OrderToRestaurant_list)<=0): continue for OrderToRestaurant in OrderToRestaurant_list: time = OrderToRestaurant.createTime total = OrderToRestaurant.total order_info = [] for order_key in OrderToRestaurant.orders: order = order_key.get() dish = order.dish.get() order_info.append((dish.name, dish.price, order.number)) OrdersToMe_info.append((("{:%a, %d %b %Y %H:%M:%S GMT}".format(time)), restaurant.name, OrderToRestaurant.user.nickname(), total, order_info)) template = JINJA_ENVIRONMENT.get_template('templates/orders_restaurant.html') template_values = { 'OrdersToMe_len': len(OrdersToMe_info), 'OrdersToMe_info': OrdersToMe_info } self.response.write(template.render(template_values))
def post(self): restaurant_name = self.request.get('restaurant_name') user = users.get_current_user() cart = CartModel.query(CartModel.user==user, CartModel.restaurant_name==restaurant_name).fetch()[0] ######################################################Send Email to restaurant########################################################### order_contents = ' ' if (len(cart.orders)>0): for order_key in cart.orders: order = order_key.get() dish = order.dish.get() dish_name = dish.name dish_quantity = order.number order_contents = order_contents + str(dish_name) + '(' + str(dish_quantity) + ')' + ' | ' user_email = user.nickname() my_email = "*****@*****.**" email_subject = "New Order for " + restaurant_name email_content = '''You have a new order with the following information: Order Contents: %s Address: %s Phone Number: %s Time: %s Notes: %s''' mail.send_mail(sender=EMAIL_SENDER, to=user_email, subject=email_subject, body=email_content % (order_contents, cart.customer_address, cart.customer_phone, cart.customer_time, cart.customer_notes)) mail.send_mail(sender=EMAIL_SENDER, to=my_email, subject=email_subject, body=email_content % (order_contents, cart.customer_address, cart.customer_phone, cart.customer_time, cart.customer_notes)) history_cart = HistoryCartModel() history_cart.restaurant_name = restaurant_name history_cart.user = user history_cart.total = cart.total history_cart.orders = cart.orders history_cart.put() cart.key.delete() self.response.write(json.dumps({'data': 'success'}))
def get(self): # self.response.write("My Orders") user = users.get_current_user() history_cart_query = HistoryCartModel.query(HistoryCartModel.user==user).order(-HistoryCartModel.createTime).fetch() history_cart_info = [] if (len(history_cart_query)>0): for history_cart in history_cart_query: restaurant_name = history_cart.restaurant_name time = history_cart.createTime total = history_cart.total order_info = [] for order_key in history_cart.orders: order = order_key.get() dish = order.dish.get() order_info.append((dish.name, dish.price, order.number)) history_cart_info.append((("{:%a, %d %b %Y %H:%M:%S GMT}".format(time)), restaurant_name, total, order_info)) template = JINJA_ENVIRONMENT.get_template('templates/myorders.html') template_values = { 'history_cart_query_len': len(history_cart_query), 'history_cart_info': history_cart_info } self.response.write(template.render(template_values))