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 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') # 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') restaurant = RestaurantModel.query(RestaurantModel.name==restaurant_name).fetch()[0] payment = restaurant.payment info = {'payment': payment} info_json = json.dumps(info) self.response.write(info_json)
def get(self): user = users.get_current_user() if (user): url = users.create_logout_url(self.request.url) url_linktext = 'Logout' restaurant_query = RestaurantModel.query(RestaurantModel.owner==user).fetch() restaurant_info = [] if (len(restaurant_query) > 0): for restaurant in restaurant_query: p1 = urllib.urlencode({'name':restaurant.name}) tmp = "/view_picture/%s" % restaurant.Blob_key tmp1 = "/viewdishes?%s" % p1 restaurant_info.append((restaurant.name, tmp, tmp1)) # current_location = 'UT-Austin' #get the current location in database # self.response.write(restaurant_info) template_values = { 'user': user, 'url': url, 'url_linktext': url_linktext, 'restaurant_query_len': len(restaurant_query), 'restaurant_info': restaurant_info } template = JINJA_ENVIRONMENT.get_template('templates/main_restaurant.html') self.response.write(template.render(template_values)) else: self.redirect('/')
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 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('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() global sort_dist if (user): u_query = UserModel.query(UserModel.user==user).fetch() if (len(u_query)>0): u = u_query[0] current_location = u.last_location lat = u.last_latitude lg = u.last_longitude url = users.create_logout_url(self.request.url) url_linktext = 'Logout' restaurant_query = RestaurantModel.query().order(-RestaurantModel.TotalScore).fetch() restaurant_info = [] if (len(restaurant_query) > 0): for restaurant in restaurant_query: a = restaurant.latitude l = restaurant.longitude tmp = "/view_picture/%s" % restaurant.Blob_key part = urllib.urlencode({'name':restaurant.name}) tmp1 = "/order?%s" % part score = restaurant.TotalScore restaurant_info.append((restaurant.name, tmp, a, l, tmp1, score)) if (sort_dist): restaurant_info.sort(key=lambda tup: (tup[2]-lat)**2+(tup[3]-lg)**2) # # Initialize a cart for this user # cart_query = CartModel.query(CartModel.user==user).fetch() # if (len(cart_query)<1): # cart = CartModel() # cart.user = user # cart.orders = [] # cart.total = 0.0 # cart.put() # current_location = 'UT-Austin' #get the current location in database template_values = { 'user': user, 'url': url, 'url_linktext': url_linktext, 'current_location': current_location, 'restaurant_query_len': len(restaurant_query), 'restaurant_info': restaurant_info } template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values)) else: self.redirect('/location') else: self.redirect('/')
def get(self): restaurant_name = self.request.get('restaurant_name') user = users.get_current_user() restaurant_query = RestaurantModel.query(RestaurantModel.owner==user, RestaurantModel.name==restaurant_name).fetch() restaurant_info = [] if (len(restaurant_query)>0): restaurant = restaurant_query[0] viewURL = '/view_picture/%s' % restaurant.Blob_key restaurant_info.append((restaurant_name, restaurant.ownerName, restaurant.location, restaurant.free_shipping, restaurant.shipping_fee, viewURL)) template = JINJA_ENVIRONMENT.get_template('viewedit.html') template_values = { } self.response.write(template.render(template_values))
def get(self): URL = '/myorders' restaurant_name = self.request.get('restaurant_name') new_score = float(self.request.get('rate_score')) restaurant_list = RestaurantModel.query(RestaurantModel.name==restaurant_name).fetch() if (len(restaurant_list) > 0): restaurant = restaurant_list[0] if (restaurant.numberOfScores <= 0): restaurant.TotalScore = 0 restaurant.TotalScore = round((restaurant.TotalScore * restaurant.numberOfScores + new_score)/(restaurant.numberOfScores + 1),2) restaurant.numberOfScores = restaurant.numberOfScores + 1 restaurant.put() self.redirect(URL)
def get(self): user = users.get_current_user() global restaurant_name 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 if (user): url = users.create_logout_url(self.request.url) url_linktext = 'Logout' order_url = "/order?name=%s" % restaurant_name # Get all the comments to the restaurant comments_list = [] comments_query = CommentModel.query(CommentModel.restaurant_name==restaurant_name).order(-CommentModel.createTime).fetch() comment_time = datetime.datetime.now() if (len(comments_query)>0): for comment in comments_query: comment_time = "{:%a, %d %b %Y %H:%M:%S GMT}".format(comment.createTime) comments_list.append((comment_time, comment.user.nickname(), comment.content)) num_of_comments = len(comments_list) template_values = { 'order_url': order_url, '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, 'user': user, 'url': url, 'url_linktext': url_linktext, 'num_of_comments': num_of_comments, 'comments_list': comments_list, } template = JINJA_ENVIRONMENT.get_template('templates/evaluate.html') self.response.write(template.render(template_values)) else: self.redirect('/')
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))
def post(self): restaurant_name = self.request.get('name') user = users.get_current_user() restaurant_list = RestaurantModel.query(RestaurantModel.owner==user, RestaurantModel.name==restaurant_name).fetch() if (len(restaurant_list) <= 0 ): restaurant = RestaurantModel() else: restaurant = restaurant_list[0] restaurant.name = self.request.get('name') restaurant.owner = users.get_current_user() restaurant.ownerName = self.request.get('ownername') restaurant.phoneNum = self.request.get('phonenumber') restaurant.location = self.request.get('location') if (self.request.get('latitude')!=""): restaurant.latitude = float(self.request.get('latitude')) if (self.request.get('longitude')!=""): restaurant.longitude = float(self.request.get('longitude')) upload_query = self.get_uploads() if len(upload_query)>0: upload = self.get_uploads()[0] restaurant.Blob_key = upload.key() restaurant.comments = [] restaurant.numberOfScores = 0 if (self.request.get('freeshipping')!=""): restaurant.free_shipping = float(self.request.get('freeshipping')) if (self.request.get('shipping')!=""): restaurant.shipping_fee = float(self.request.get('shipping')) restaurant.payment = self.request.get('paypal') restaurant.put() # self.redirect('/view_picture/%s' % restaurant.Blob_key) # img = self.request.get('img') # img = images.resize(img, 64,64) # restaurant.coverPage = img self.redirect('/main_restaurant')