def desserts(): if flask.request.method == 'POST': form = flask.request.form API.add_product_to_order(form) return flask.redirect(flask.url_for('desserts')) cart = API.get_cart_data(1) des = API.get_desserts() return flask.render_template("desserts.html.jinja2", products=des, cart=cart)
def boissons(): if flask.request.method == 'POST': form = flask.request.form API.add_product_to_order(form) return flask.redirect(flask.url_for('boissons')) cart = API.get_cart_data(1) drinks = API.get_drinks() return flask.render_template("boissons.html.jinja2", products=drinks, cart=cart)
def sandwichs(): if flask.request.method == 'POST': form = flask.request.form API.add_product_to_order(form) return flask.redirect(flask.url_for('sandwichs')) cart = API.get_cart_data(1) sandwiches = API.get_sandwiches() return flask.render_template("sandwiches.html.jinja2", products=sandwiches, cart=cart)
def backend(): if request.method == 'POST': title = request.form.get('title') food_type = request.form.get('food_type') price = request.form.get('price') stock = request.form.get('stock') products0 = Products(name=title, food_type=food_type, price=price, stock=stock) API.add_products([products0]) flash('Item created') return redirect(url_for("backend")) products = Products.query.all() return flask.render_template("bacckend.html", products=products)
def edit_order(order_id): order = API.get_order_by_id(order_id) if flask.request.method == 'POST': form = flask.request.form paid = form.get('paid') == 'True' delivered = form.get('delivered') == 'True' print(form) print(delivered ,paid) order.delivered = delivered order.paid = paid db.session.commit() return flask.redirect(flask.url_for("edit_order", order_id = order_id)) ord = API.get_order_data(order_id) return flask.render_template("order_edition.html.jinja2", order = order, order_list = ord, order_id = order_id)
def admin_add_api(admin_pass): if request.method == 'GET': error = False # try: newRobot = API(robot_name=robot_name, robot_image=image) robot_name = newRobot.robot_name robot_image = newRobot.robot_image db.session.add(newRobot) db.session.commit() except: db.session.rollback() error = True # debug on make it return not print #print(sys.exc_info()) return str(sys.exc_info()) system_error_message = sys.exc_info() finally: db.session.close() if not error: print('Hello Robot') message = 'Great You Create Your New Robot WIth name: ' + str( robot_name) message += '<br /> <br /><img width="200" height="200" src="/static/' + str( robot_image) + '">' return message else: return 'hi error'
def create_robot(robot_name, image): if request.method == 'GET': error = False # try: newRobot = Robot(robot_name=robot_name, robot_image=image) robot_name = newRobot.robot_name robot_image = newRobot.robot_image db.session.add(newRobot) store_for_robot = APIStore(robot_id=newRobot.id) db.session.add(store_for_robot) # it should be user api or get u and let him pay better and easier apikey = 'db6608063a9d72758e29ea323da07bd1' api = API(name='Current Weather Data', baseurl='api.openweathermap.org/data/2.5/weather?', baseurl1='api.openweathermap.org/data/2.5/find?', api_key=apikey, query0='id', query1='zip', query2='q', query3='units', query4='lang', query5='mode', query6='cnt', query7='lat', query8='lon', query9='cnt', api_price='1', api_description='Access current weather data\ for any location including over 200,000 cities\ We collect and process weather data from different\ sources such as global and local weather models,\ satellites, radars and vast network of weather stations\ JSON, XML, and HTML formats Available for both Free and paid subscriptions', apid_document='https://openweathermap.org/current', api_image='logo_white_cropped.png', store_id=store_for_robot.id, robot_id=newRobot.id) db.session.commit() except: db.session.rollback() error = True # debug on make it return not print #print(sys.exc_info()) return str(sys.exc_info()) system_error_message = sys.exc_info() finally: db.session.close() if not error: print('Hello Robot') message = 'Great You Create Your New Robot WIth name: ' + str( robot_name) message += '<br /> <br /><img width="200" height="200" src="/static/' + str( robot_image) + '">' message += '<br /> You Can Access Your API Sore And make your robot learn new APIs and do good things ' return message else: return 'hi error'
def delete_product(product_id): product = API.get_product_by_ID(product_id) if product != None: try: db.session.delete(product) db.session.commit() except Exception as e: print(e) flash('err delete') else: flash('not found') return redirect(url_for('backend'))
def menus(): menu_prices_list, sandwich_dict = API.get_menu_prices() drinks = API.get_drinks() des = API.get_desserts() if flask.request.method == 'POST': form = flask.request.form API.add_menu_to_order(form) return flask.redirect(flask.url_for('menus')) cart = API.get_cart_data(1) return flask.render_template("menus.html.jinja2", menus_list=menu_prices_list, sandwich_dict=sandwich_dict, drinks=drinks, des=des, cart=cart)
def out_of_stock(): cart = API.get_cart_data(1) return flask.render_template("outofstock.html.jinja2",cart = cart)
def validate(order_id): validation = API.validate_order(order_id) if not validation: API.delete_order(order_id) return flask.redirect(flask.url_for("out_of_stock")) return flask.redirect(flask.url_for("home"))
def home(): cart = API.get_cart_data(1) return flask.render_template("home.html.jinja2", cart=cart)
def delete_order_item(order_item_id,order_id): API.delete_order_item(order_item_id) return flask.redirect(flask.url_for("edit_order", order_id= order_id))
def orders(): ord = API.get_all_validated_orders() return flask.render_template("orders.html.jinja2", orders = ord)