Exemplo n.º 1
0
def restaurant_menu_update(name):
	response = make_response(render_template('404.html'))
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	menu_id = request.args.get('menu_id')
	restaurant_id = request.args.get('restaurant_id')
	menu_item_id = request.args.get('menu_item_id')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Manager':
			form = MenuItemForm()
			if form.validate_on_submit():
				flag, result = furls.restaurant_menu_update(restaurant_id, menu_id, menu_item_id, form.data)
				if flag:
					response = redirect(url_for('main.restaurant_menu', name=name, result_message='Updated'))
				else:
					response = redirect(url_for('main.restaurant_menu_edit', name=name, \
					error_message=result['message'],menu_id=menu_id,\
					restaurant_id=restaurant_id,menu_item_id=menu_item_id))
			else:
				flag, restr_result = furls.restaurant_info(result['user_id'])
				form.title.default = request.args.get('title')
				form.price.default = request.args.get('price')
				form.info.default = request.args.get('info')
				form.process()
				response = make_response(render_template('restaurant_menu_edit.html',user=restr_result, form=form,\
				error_message=error_message,result_message=result_message,menu_id=menu_id,\
				restaurant_id=restaurant_id,menu_item_id=menu_item_id))
			response.set_cookie('session_id', session_id)
	return response
Exemplo n.º 2
0
def restaurant_menu(name):
	response = make_response(render_template('404.html'))
	session_id = request.cookies.get('session_id')
	result_message = request.args.get('result_message')
	error_message = request.args.get('error_message')
	if session_id:
		flag, result = furls.auth_session_state(session_id)
		if flag and result['role'] == 'Manager':
			session_id = result['session_id']
			if flag:
				form = MenuItemForm()
				if form.validate_on_submit():
					menu_id = request.args.get('menu_id')
					restaurant_id = request.args.get('restaurant_id')
					flag, result = furls.restaurant_menu_item_create(restaurant_id, menu_id, form.data)
					if flag:
						response = redirect(url_for('main.restaurant_menu', name=name, result_message='Created!'))
					else:
						response = redirect(url_for('main.restaurant_menu', name=name,\
							error_message=result['message']))
				else:
					flag, restr_result = furls.restaurant_info(result['user_id'])
					flag, menu = furls.restaurant_menu(result['user_id'])
					if form.errors:	error_message = 'Incorrect values'			
					response = make_response(render_template('restaurant_menu.html',\
						user=restr_result, menu_data=menu,form=form,\
						error_message=error_message,result_message=result_message))
			response.set_cookie('session_id', session_id)
	return response
Exemplo n.º 3
0
def new_menu():
    form = MenuItemForm()

    if form.validate_on_submit():
        name = form.name.data
        price = form.price.data
        desc = form.desc.data
        photo = form.photo.data
        photo_name = secure_filename(photo.filename)
        photo_path = os.path.join('static/images/menus', photo_name)
        thumb_path = os.path.join('static/images/menus/thumbs', photo_name)
        thumb_size = 128, 128

        menu = db.engine.execute(
            text(
                "SELECT * FROM menus WHERE menu_name = :name AND menu_price = :price LIMIT 1"
            ), {
                "name": name,
                "price": price
            }).first()

        # add new staff if not exists
        if menu is None:
            # save staff photo
            photo.save(photo_path)

            # create thumbnail for staff
            try:
                im = Image.open(photo_path)
                im.thumbnail(thumb_size, Image.ANTIALIAS)
                im.save(thumb_path, "JPEG")
            except IOError:
                flash("cannot create thumbnail for this menu item")

            # save user and the thumbnail name
            insertSql = "INSERT INTO menus (menu_name, menu_price, menu_desc, menu_photo) VALUES (:mname, :mprice, :mdesc, :mphoto)"
            insertParams = {
                'mname': name,
                'mprice': price,
                'mdesc': desc,
                'mphoto': photo_name
            }
            db.engine.execute(text(insertSql), insertParams)

            flash('New menu item added successfully.')
            return redirect(url_for('menus'))

        else:
            flash('Menu item already exists.')

    return render_template('new-menu-item.html',
                           auth=current_user,
                           form=form,
                           async_mode=socketio.async_mode)
def deleteMenuItem(restaurant_id, menu_id):
    session = DBSession()
    form = MenuItemForm()
    menuItemToDelete = session.query(Menu).filter_by(id=menu_id).one()
    if form.validate_on_submit():
        session.delete(menuItemToDelete)
        session.commit()
        session.close()
        flash("Menu Item Deleted Successfully!!! ")
        return redirect(url_for('viewRestaurantDetails', restaurant_id=restaurant_id))

    return render_template('menu/deletemenu.html', item = menuItemToDelete, form=form)
def createMenuItem(restaurant_id):
    session = DBSession()
    form = MenuItemForm()
    if form.validate_on_submit():
        name = form.name.data
        course = form.course.data
        category = form.category.data
        price = form.price.data
        description = form.description.data
        menuItem = models.Menu(name=name, course =course, category=category, description = description, price= price, restaurant_id=restaurant_id)
        session.add(menuItem)
        session.commit()
        session.close()
        flash("Added {} ".format(name))
        return redirect(url_for('viewRestaurantDetails', restaurant_id = restaurant_id))

    return render_template('menu/createmenu.html', form=form)
def editMenuItem(restaurant_id, menu_id):
    session = DBSession()
    form = MenuItemForm()
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    editedMenu = session.query(Menu).filter_by(id=menu_id).one()
    if form.validate_on_submit():
        if request.form['name']:
            editedMenu.name = form.name.data
        if request.form['course']:
            editedMenu.course = form.course.data
        if request.form['category']:
            editedMenu.category = form.category.data
        if request.form['price']:
            editedMenu.price = form.price.data
        if request.form['description']:
            editedMenu.description = form.description.data
        session.add(editedMenu)
        session.commit()
        session.close()
        flash("Menu Item Successfully Edited")
        return redirect(url_for('viewRestaurantDetails', restaurant_id = restaurant_id))

    return render_template('menu/editmenu.html', restaurant_id = restaurant_id, menu_id=menu_id, item=editedMenu, form=form)