def get(self): user = users.get_current_user() restaurant_name = self.request.get('name') # generate a cart cart_query = CartModel.query(CartModel.restaurant_name==restaurant_name, CartModel.user==user).fetch() if (len(cart_query)<1): cart = CartModel() cart.user = user cart.restaurant_name = restaurant_name cart.orders = [] cart.total = 0 cart.put() # self.response.write(restaurant_name) restaurant = RestaurantModel.query(RestaurantModel.name==restaurant_name, RestaurantModel.owner==user).fetch()[0] key = restaurant.key dish_query = DishModel.query(ancestor=key).fetch() dish_info = [] if (len(dish_query)>0): for dish in dish_query: tmp = "/view_picture/%s" % dish.picture_key dish_info.append((dish.name, dish.price, tmp, dish.description)) part = urllib.urlencode({'name': restaurant_name}) add_url = '/add_dish?%s' % part # self.response.write(restaurant_name) template = JINJA_ENVIRONMENT.get_template('templates/viewdishes.html') template_values ={ 'dish_query_len': len(dish_query), 'dish_info': dish_info, 'add_url': add_url, 'restaurant_name': restaurant_name } 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): user = users.get_current_user() carts_query = CartModel.query(CartModel.user==user).fetch() carts_info = [] length = len(carts_query) if (len(carts_query)>0): for cart in carts_query: if (cart.total <= 0): length = length - 1 cart.key.delete() continue restaurant_name = cart.restaurant_name total = cart.total part = urllib.urlencode({'name': restaurant_name}) cart_url = '/viewsinglecart?%s' % part # for order_key in cart.orders: # order = order_key.get() # dish = order.dish.get() # dish_name = dish.name # dish_price = dish.price carts_info.append((restaurant_name, total, cart_url)) template = JINJA_ENVIRONMENT.get_template('templates/viewcart.html') template_values = { 'cart_query_len': length, 'cart_info': carts_info } self.response.write(template.render(template_values))
def get(self): user = users.get_current_user() restaurant_name = self.request.get('restaurant_name') # self.response.write(restaurant_name) restaurant = RestaurantModel.query(RestaurantModel.name == restaurant_name).fetch()[0] # str = restaurant.payment str = quopri.decodestring(restaurant.payment) cart = CartModel.query(CartModel.user==user, CartModel.restaurant_name==restaurant_name).fetch()[0] cart_id = cart.key.id() ######################################################Save the customer information (user address|phone|notes)########################################################### cart.customer_address = self.request.get('customer_address') cart.customer_phone = self.request.get('customer_phone') cart.customer_time = self.request.get('customer_time') cart.customer_notes = self.request.get('customer_notes') cart.put() shipping_fee = restaurant.shipping_fee template = JINJA_ENVIRONMENT.get_template('templates/confirm.html') template_values = { 'restaurant_name': restaurant_name, 'total_cost': cart.total, 'shipping_fee': shipping_fee, 'payment': str, 'cart_id': cart_id, 'customer_address': cart.customer_address, 'customer_phone': cart.customer_phone, 'customer_time': cart.customer_time, 'customer_notes': cart.customer_notes, } self.response.write(template.render(template_values))
def get(self): user = users.get_current_user() restaurant_name = self.request.get('name') restaurant = RestaurantModel.query(RestaurantModel.name==restaurant_name).fetch()[0] cart_query = CartModel.query(CartModel.restaurant_name==restaurant_name, CartModel.user==user).fetch() cart_info = [] str = restaurant.payment # self.response.write(str) if (len(cart_query)>0): cart = cart_query[0] cart_total = cart.total if (len(cart.orders)>0): for order_key in cart.orders: order = order_key.get() dish = order.dish.get() dish_name = dish.name dish_price = dish.price quantity = order.number p = urllib.urlencode({'id':order_key.id(),'restaurant_name':restaurant_name}) cancel_url = "/cancel?%s" % p cart_info.append((dish_name, dish_price, quantity, order_key.id(), cancel_url)) # part = urllib.urlencode({'restaurant_name': restaurant_name}) # confirm_url = '/confirm?%s' % part confirm_url = '/confirm' template = JINJA_ENVIRONMENT.get_template('templates/viewsinglecart.html') template_values = { 'restaurant_name': restaurant_name, 'cart_query_len': len(cart_query), 'paypal': restaurant_name, 'paypal_button': str, 'cart_info': cart_info, 'cart_total': cart_total, 'confirm_url': confirm_url } self.response.write(template.render(template_values))
def get(self): user = users.get_current_user() restaurant_name = self.request.get('restaurant_name') dish_name = self.request.get('dish_name') dish_price = float(self.request.get('dish_price')) quantity = int(self.request.get('quantity')) found = False restaurant = RestaurantModel.query(RestaurantModel.name==restaurant_name).fetch()[0] dish_query = DishModel.query(DishModel.name==dish_name, ancestor=restaurant.key).fetch() # self.response.write(dish_query[0].name) if (len(dish_query)>0): dish = dish_query[0] cart_query = CartModel.query(CartModel.user==user, CartModel.restaurant_name==restaurant_name).fetch() if (len(cart_query)>0): cart = cart_query[0] name = [] for order_key in cart.orders: # order = OrderModel.get_by_id(order_key.id()) order = order_key.get() dish_tmp = order.dish.get() # name.append(order.dish.get().name) if (dish_tmp.name==dish_name): # self.response.write("get!!") order.number = order.number + quantity order.put() cart.total = cart.total + dish_price*quantity cart.put() found = True self.redirect("/order?name=%s" % restaurant.name) if (found == False): new_order = OrderModel() new_order.number = quantity new_order.dish = dish.key key = new_order.put() cart.orders.append(key) cart.total = cart.total + dish_price*quantity cart.put() self.redirect("/order?name=%s" % restaurant.name) else: new_order = OrderModel() new_order.number = quantity new_order.dish = dish.key key = new_order.put() cart = CartModel() cart.orders = [] cart.orders.append(key) cart.total = quantity*dish.price cart.restaurant_name = restaurant_name cart.user = user cart.put() self.redirect("/order?name=%s" % restaurant.name) # self.redirect('/main') else: self.redirect('/main')
def post(self): user = users.get_current_user() dish_name = self.request.get('dish_name') restaurant_name = self.request.get('restaurant_name') id = int(self.request.get('id')) cart = CartModel.query(CartModel.user==user, CartModel.restaurant_name==restaurant_name).fetch()[0] order = OrderModel.get_by_id(id) order.number = order.number + 1 order.put() dish = order.dish.get() cart.total = cart.total + dish.price cart.put() # url = "/test?name=%s" % dish_name info = {"name": dish_name, "other": restaurant_name, "id":id, 'total': cart.total} info_json = json.dumps(info) self.response.write(info_json)
def get(self): user = users.get_current_user() restaurant_name = self.request.get('restaurant_name') id = int(self.request.get('id')) order = OrderModel.get_by_id(id) cart_query = CartModel.query(CartModel.restaurant_name==restaurant_name, CartModel.user==user).fetch() if (len(cart_query)>0): dish = order.dish.get() cart = cart_query[0] cart.orders.remove(order.key) cart.total = cart.total - order.number*dish.price cart.put() order.key.delete() p = urllib.urlencode({'name':restaurant_name}) URL = '/viewsinglecart?%s' % p self.redirect(URL) else: self.redirect('/error')