def status(ID, id): try: status = system.check_status(int(id)) except InvalidID as err: order_is_ready = err.get_message() return render_template('check_order.html', ID=ID, id=id, ready=order_is_ready) order = system.get_order(int(id)) if order is None: order = system.get_completed_order(int(id)) if (order.get_confirmed() == False): order_is_ready = 'No order exists for ID of ' + id elif (system.check_status(int(id)) == True): order_is_ready = True else: order_is_ready = False return render_template('check_order.html', ID=ID, id=id, ready=order_is_ready)
def check_order_in_session(): # check whether order_id in the session if 'order_ID' not in session: return render_template("error.html", error="Sorry, you need to create a new order first.") # check whether the order_id is in the system if not system.get_order(session['order_ID']): return render_template("error.html", error="Sorry, your order ID is no longer valid.")
def wrap(ID): items = system.get_main_list() if (request.method == 'POST'): if (system.get_order(int(ID)) == None): system.new_order(int(ID)) wrap = Wrap() for ingredient in items: if ("bun" not in ingredient): if (int(request.form[ingredient]) != 0): wrap.add_ingredient(ingredient, int(request.form[ingredient])) if (wrap.is_valid_main() == False): errors = wrap.get_errors() return render_template('wrap.html', items=items, errors=errors, ID=ID, form=request.form) else: system.add_to_order(wrap, int(ID)) return render_template('item_confirm.html', item="Custom Wrap", ID=ID) return render_template('wrap.html', items=items, ID=ID)
def order_detail(order_id): order_id = int(order_id) order = system.get_order(order_id) if (order is None): abort(404) return render_template('order_detail.html', order=order, menu=system.menu, confirmed=True, errors=None)
def order(ID): customer_order = system.get_order(int(ID)) if customer_order is None: return redirect(url_for('error', ID=ID)) mains = [] sides = {} drinks = {} main_type = [] order_items = customer_order.get_order_list() total_price = customer_order.total_price() for item in order_items: if (isinstance(item, Drink)): if (item.get_name() in drinks): drinks[item.get_name()] += 1 else: drinks[item.get_name()] = 1 elif (isinstance(item, Side)): if (item.get_name() in sides): sides[item.get_name()] += 1 else: sides[item.get_name()] = 1 else: mains.append(item.get_ingredients()) main_type.append(item.type_main()) if (request.method == 'POST'): try: success, customer_ID = system.confirm_order(customer_order) except OrderError as err: success = err.get_message() if success != True: return render_template('order.html', ID=ID, mains=mains, main_type=main_type, sides=sides, drinks=drinks, price=total_price, errors=success) else: return render_template('order_confirmed.html', ID=ID) return render_template('order.html', ID=ID, mains=mains, main_type=main_type, sides=sides, drinks=drinks, price=total_price)
def drinks(ID): drinklist = system.get_drinklist() if request.method == 'POST': if (system.get_order(int(ID)) == None): system.new_order(int(ID)) for drink in drinklist: for i in range(int(request.form[drink])): system.add_to_order(Drink(drink), int(ID)) return render_template('item_confirm.html', item="Drinks", ID=ID) return render_template('drinks.html', drinklist=drinklist, ID=ID)
def sides(ID): sidelist = system.get_sidelist() if request.method == "POST": if (system.get_order(int(ID)) == None): system.new_order(int(ID)) for side in sidelist: for i in range(int(request.form[side])): system.add_to_order(Side(side), int(ID)) return render_template('item_confirm.html', item="Sides", ID=ID) return render_template('sides.html', sidelist=sidelist, ID=ID)
def review_order(): check_order_in_session() order = system.get_order(session['order_ID']) if request.method == 'POST': if request.form["button"] == "checkout": order_id = session['order_ID'] error = system.checkout(order_id) if error: return render_template("error.html", error=error) session.pop('order_ID') return render_template("customer_order_result.html", order_id=order_id) else: system.del_items_in_orders(order.order_id, request.form["button"]) return render_template('customer_review_order.html', order=order)
def serve_order(order_id): order = system.get_order(int(order_id)) if request.method == 'POST': if request.form["submit"] == "Mark Finished": system.checkout(int(order_id)) return render_template("order_detail.html", order=order, menu=system.menu, confirmed=True, errors=None, for_staff=False) elif request.form['submit'] == 'Back': return redirect(url_for('order_list')) return render_template("order_detail.html", order=order, menu=system.menu, confirmed=True, errors=None, for_staff=True)
def burger(ID): items = system.get_main_list() if (request.method == 'POST'): if (system.get_order(int(ID)) == None): system.new_order(int(ID)) if (request.form['burger_tier'] == 'single'): burger = SingleBurger() elif (request.form['burger_tier'] == 'double'): burger = DoubleBurger() elif (request.form['burger_tier'] == 'triple'): burger = TripleBurger() for ingredient in items: if (int(request.form[ingredient]) != 0): burger.add_ingredient(ingredient, int(request.form[ingredient])) if (burger.is_valid_main() == False): errors = burger.get_errors() return render_template('burger.html', items=items, errors=errors, ID=ID, form=request.form) else: system.add_to_order(burger, int(ID)) return render_template('item_confirm.html', item="Custom Burger", ID=ID) return render_template('burger.html', items=items, ID=ID)
def selection(ID, main): if (request.method == 'POST'): if (request.form["type"] == "Custom Burger"): return redirect(url_for("burger", ID=ID, main=main)) elif (request.form["type"] == "Custom Wrap"): return redirect(url_for("wrap", ID=ID, main=main)) elif (request.form["type"] == "Python2 Burger"): burger = DoubleBurger() burger.add_ingredient("Beef patty", 2) burger.add_ingredient("Cheddar cheese", 2) burger.add_ingredient("BBQ sauce", 2) burger.add_ingredient("Muffin bun", 3) if (system.get_order(int(ID)) == None): system.new_order(int(ID)) system.add_to_order(burger, int(ID)) return render_template('item_confirm.html', item="Python2 Burger", ID=ID) elif (request.form["type"] == "Python3 Burger"): burger = TripleBurger() burger.add_ingredient("Beef patty", 3) burger.add_ingredient("Cheddar cheese", 3) burger.add_ingredient("BBQ sauce", 3) burger.add_ingredient("Sesame bun", 4) if (system.get_order(int(ID)) == None): system.new_order(int(ID)) system.add_to_order(burger, int(ID)) return render_template("item_confirm.html", item="Python3 Burger", ID=ID) elif (request.form["type"] == "George's Burger"): burger = DoubleBurger() burger.add_ingredient("Beef patty", 1) burger.add_ingredient("Chicken patty", 1) burger.add_ingredient("Swiss cheese", 2) burger.add_ingredient("Sesame bun", 3) burger.add_ingredient("Onions", 3) burger.add_ingredient("Tomato sauce", 2) burger.add_ingredient("Lettuce", 2) if (system.get_order(int(ID)) == None): system.new_order(int(ID)) system.add_to_order(burger, int(ID)) return render_template("item_confirm.html", item="George's Burger", ID=ID) elif (request.form["type"] == "Beef Wrap"): wrap = Wrap() wrap.add_ingredient("Beef patty", 1) wrap.add_ingredient("Lettuce", 3) wrap.add_ingredient("Onions", 3) wrap.add_ingredient("Tomatoes", 3) wrap.add_ingredient("BBQ sauce", 1) if (system.get_order(int(ID)) == None): system.new_order(int(ID)) system.add_to_order(wrap, int(ID)) return render_template("item_confirm.html", item="Beef Wrap", ID=ID) elif (request.form["type"] == "Chicken Wrap"): wrap = Wrap() wrap.add_ingredient("Chicken patty", 1) wrap.add_ingredient("Lettuce", 3) wrap.add_ingredient("Onions", 3) wrap.add_ingredient("Tomatoes", 3) wrap.add_ingredient("BBQ sauce", 1) if (system.get_order(int(ID)) == None): system.new_order(int(ID)) system.add_to_order(wrap, int(ID)) return render_template("item_confirm.html", item="Chicken Wrap", ID=ID) elif (request.form["type"] == "Vegetarian Wrap"): wrap = Wrap() wrap.add_ingredient("Vegetarian patty", 1) wrap.add_ingredient("Lettuce", 3) wrap.add_ingredient("Onions", 3) wrap.add_ingredient("Tomatoes", 3) wrap.add_ingredient("BBQ sauce", 1) if (system.get_order(int(ID)) == None): system.new_order(int(ID)) system.add_to_order(wrap, int(ID)) return render_template("item_confirm.html", item="Vegetarian Wrap", ID=ID) return render_template('selection.html', ID=ID, main=main)
def search_order(order_id): return render_template('customer_search_order_result.html', order=system.get_order(int(order_id)))
def order(): if request.method == "POST": oid = request.form["order"] order = system.get_order(oid) if request.form["form"] == "pageForm": if request.form["submit_button"] == "creations": return render_template('creations.html', order=order, id=oid) elif request.form["submit_button"] == "sides": items = system.inventory.sides return render_template('sides.html', items=items, order=order, id=oid) elif request.form["submit_button"] == "drinks": items = system.inventory.drinks return render_template('drinks.html', order=order, id=oid, items=items) elif request.form["submit_button"] == "checkout": return render_template('payment.html', order=order, id=oid) elif request.form["form"] == "creation_type": if request.form["submit_button"] == "standard": standard = True items = system.standard_creations return render_template('creations.html', standard=standard, items=items, id=oid) elif request.form["submit_button"] == "custom": items = system.inventory.ingredients return render_template('creations.html', custom=True, items=items, id=oid) elif request.form["form"] == "standard_creation": items = system.standard_creations form = StandardCreationForm(request.form, system) # get errors with ingredients (check as normal ingredients) if len(form.errors) > 0: messages = [ "The selected item is currently unavailable. Please select a different option" ] return render_template('creations.html', messages=messages, items=items, id=oid, standard=True) # if no errors flash a 'Successfully added to order' message messages = [ "Successfully added {} to order".format(form.creation.name) ] order.add_creation(form.creation) system.remove_inventory_creation(form.creation) # if errors re-show page with error messages return render_template('creations.html', messages=messages, standard=True, items=items, id=oid) elif request.form["form"] == "custom_creation": # convert form into a form class?? form = CustomOrderForm(request.form, system.inventory) items = system.inventory.ingredients # check for any errors if len(form.errors) > 0: messages = ["Errors in order. Please try again"] return render_template('creations.html', form=request.form, errors=form.errors, messages=messages, items=items, id=oid, custom=True) # if no errors add to order and include a 'Successfully added to order' message creation = form.create_creation() order.add_creation(creation) system.remove_inventory_creation(creation) messages = ["Successfully added Custom Creation to order"] return render_template('creations.html', messages=messages, items=items, id=oid) elif request.form["form"] == "add_sides": # convert to dictionary of sides and amounts form = CustomSidesForm(request.form, system.inventory) item = system.inventory.sides # check for errors if len(form.errors) > 0: messages = ["Errors in order. Please try again"] return render_template('sides.html', form=request.form, errors=form.errors, messages=messages, items=item, id=oid) # re-show page with errors /flash successful message sides = form.add_side(order) for s in sides: side = system.inventory.get_side(s) system.remove_inventory_item(side, int(sides[s])) messages = ["Successfully added the sides to the order"] return render_template('sides.html', messages=messages, items=item, id=oid) elif request.form["form"] == "add_drinks": # convert to dictionary of sides and amounts form = CustomDrinkForm(request.form, system.inventory) item = system.inventory.drinks # check for errors and displays them if len(form.errors) > 0: messages = ["Errors in order. Please try again"] return render_template('drinks.html', form=request.form, errors=form.errors, messages=messages, items=item, id=oid) # if no errors add to order and include a 'Successfully added to order' message drinks = form.add_drink(order) for d in drinks: drink = system.inventory.get_drink(d) system.remove_inventory_item(drink, int(drinks[d])) messages = ["Successfully added the drinks to the order"] return render_template('drinks.html', messages=messages, items=item, id=oid) elif request.form["form"] == "confirmation": if request.form["submit_button"] == "cancel": system.readd_to_inventory(order) system.remove_order(order) return render_template('home.html') system.confirm_order(order) return render_template('order_confirmation.html', pass_id=oid) else: order = system.add_order() return render_template('order.html', order=order, id=order.id)