def post(self): user = users.get_current_user() upload = self.get_uploads()[0] restaurant_name = self.request.get('restaurant_name') dish_name = self.request.get('dish_name') restaurant_query = RestaurantModel.query(RestaurantModel.name==restaurant_name, RestaurantModel.owner==user).fetch() if (len(restaurant_query)>0) : # u = "%s" % user # self.response.write(restaurant_name +" " + u) restaurant = restaurant_query[0] key = restaurant.key dish_list = DishModel.query(DishModel.name==dish_name, ancestor=key).fetch() if (len(dish_list) <= 0): dish = DishModel(parent=restaurant.key) else: dish = dish_list[0] dish.name = dish_name dish.price = float(self.request.get('dish_price')) dish.description = self.request.get('dish_description') dish.picture_key = upload.key() dish.put() #self.redirect('/main_restaurant') self.redirect('/viewdishes?name=%s' %restaurant_name) else: self.redirect('/error')
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 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 get(self): user = users.get_current_user() restaurant_name = self.request.get('name') restaurant = RestaurantModel.query(RestaurantModel.name==restaurant_name).fetch()[0] restaurant_img = "/view_picture/%s" % restaurant.Blob_key restaurant_score = restaurant.TotalScore restaurant_phone = restaurant.phoneNum restaurant_shippingfee = restaurant.shipping_fee restaurant_freeshipping = restaurant.free_shipping restaurant_location = restaurant.location dish_query = DishModel.query(ancestor=restaurant.key).fetch() dish_info = [] if (len(dish_query)>0): for dish in dish_query: pic_url = '/view_picture/%s' % dish.picture_key # p = urllib.urlencode({'restaurant_name':restaurant_name, 'dish_name': dish.name, 'dish_price': dish.price}) # add_cart_url = "/cart?%s" % p dish_info.append((dish.name, dish.price, pic_url, dish.description)) template = JINJA_ENVIRONMENT.get_template('templates/order.html') part = urllib.urlencode({'name':restaurant_name}) evaluate_url = "/evaluate?%s" % part template_values = { 'evaluate_url': evaluate_url, 'dish_query_len': len(dish_query), 'restaurant_name': restaurant_name, 'restaurant_img': restaurant_img, 'restaurant_score': restaurant_score, 'restaurant_phone': restaurant_phone, 'restaurant_shippingfee': restaurant_shippingfee, 'restaurant_freeshipping': restaurant_freeshipping, 'restaurant_location': restaurant_location, 'dish_info': dish_info } self.response.write(template.render(template_values))