예제 #1
0
def newMenuItem(restaurant_id):
    """
    :param restaurant_id:
    :return: Allows the user to create a new menu item for the restaurant with the ID specified
    """
    if 'username' not in login_session:
        return redirect('/login')

    # Get the restaurant, items and creator
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    items = session.query(MenuItem).filter_by(restaurant_id = restaurant.id)
    creator = getUserInfo(restaurant.user_id)

    # checks to see if the user is logged in or not
    if 'username' not in login_session or creator.id != login_session['user_id']:
        flash('Only the creator of the restaurant can create a new menu item.')
        return render_template('final_showrestaurant.html', restaurant=restaurant, items=items, CREATOR=creator)

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'])
        newItem.price = request.form['price']
        newItem.description = request.form['description']
        newItem.course = request.form['course']
        newItem.restaurant_id = restaurant_id
        # newItem.user = login_session['user_id']
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created", "success")
        return redirect( url_for('showRestaurant', restaurant_id = restaurant_id) )
    else:
        return render_template('final_newmenuitem.html', restaurant_id=restaurant_id)
예제 #2
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    if login_session['user_id'] != restaurant.user_id:
        return """<script>
        function myFunction() {alert('You are not authorized to add new item to this restaurant.'); 
        window.location.href = '/restaurants/%d/';}
        </script>
        <body onload='myFunction()'> """ % restaurant_id
    if request.method == 'POST':
        newItem = MenuItem(name = request.form['name'], restaurant_id = restaurant_id, 
            description=request.form['description'], price=request.form['price'], 
            course=request.form['course'], user_id=restaurant.user_id)
        # uploads and saves the file in directory and the name of the file is stored in the database
        if request.files['picture_file']:
            filename = upload_file(restaurant_id)
            savedFile = str(filename)
            newItem.picture = savedFile
        session.add(newItem)
        session.commit()
        flash("new menu item created")
        return redirect(url_for('restaurantMenu', restaurant_id = restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        newItem = MenuItem(name = request.form['name'], restaurant_id = restaurant_id)
        newItem.description = request.form['description']
        newItem.price = request.form['price']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("Menu Item Created!")
        return redirect(url_for('showMenu', restaurant_id = restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id = restaurant_id)
def newMenuItem(restaurant_id):
    if request.method == 'POST':
        r = MenuItem()
        r.name = request.form['name']
        r.description = request.form['description']
        r.price = request.form['price']
        r.restaurant_id = restaurant_id
        session.add(r)
        session.commit()
        flash('new item %s created!' % r)
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
def createRestaurantMenu(restaurant_id):  
    if request.method == 'POST':        
        if request.form.get('name',None):         
            newItem = MenuItem(name=request.form['name'], restaurant_id=restaurant_id) 
            if request.form.get('description', None):
                newItem.description = request.form['description']        
            if request.form.get('price', None):
                newItem.price = request.form['price']  
            if request.form.get('course', None):
                newItem.course = request.form['course'] 
            session.add(newItem)
            session.commit()
            flash("A New Menu created!")         
            return redirect(url_for('showRestaurantMenu', restaurant_id = restaurant_id ))                    
    return render_template('newmenuitem.html', restaurant_id = restaurant_id) 
def newMenuItem(restaurant_id):
	restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
	if request.method == "POST":
		if request.form['name']:
			newItem = MenuItem(name = request.form['name'], restaurant_id= restaurant_id)
			newItem.price = '$' + request.form['price']
			newItem.description = request.form['description']
			session.add(newItem)
			session.commit()
			flash("New Menu Item Created!") #a session based message
			return redirect(url_for('menuHome',restaurant_id=restaurant_id))
		else:
			flash("Please enter an item name")
			return redirect(url_for('newMenuItem',restaurant_id=restaurant_id, buttons=config.item_type))
	else:
		return render_template('newMenuItem.html', restaurant=restaurant, buttons=config.item_type)
예제 #7
0
def newMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')
    editedRestaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if editedRestaurant.user_id != login_session['user_id']:
        return "<script> function myfunction() {alert('You are not authorized to edit this restaurant. Please create your own restaurant in order to edit.');}</script><body onload='myfunction()''>"
    if request.method == 'POST':
        newItem = MenuItem(name = request.form['name'], restaurant_id = restaurant_id, user_id = login_session['user_id'])
        newItem.description = request.form['description']
        newItem.price = request.form['price']
        newItem.course = request.form['course']
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created!")
        return redirect(url_for('restaurantMenu', restaurant_id = restaurant_id))
    else:
        return render_template('form.html', restaurant_id = restaurant_id)
def newMenuItem(restaurant_id):
    """

    Args:
        restaurant_id: An integer value corresponding to an existing restaurant

    Returns: Responds to the user request to show the page for creating a new menu item and also handles the posted
    attempt at creating the new menu item

    """
    # First, make sure the user is authenticated (cannot create a new menu item if not logged in)
    if not isLoggedIn():
        return redirect('/login')

    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()

    # Receive the attempt to create the new menu item or return the page for the user to create one
    if request.method == 'POST':
        # Validate the form
        if not formHasMember(request.form, 'name'):
            flash("new menu items must have a name")
        else:
            newItem = MenuItem(
                name=request.form['name'],
                description=request.form['description'],
                price=request.form['price'],
                course=request.form['course'],
                restaurant_id=restaurant_id,
                user_id=login_session['user_id']
            )
            if formHasMember(request.form, 'picture'):
                newItem.picture = request.form['picture']

            session.add(newItem)
            session.commit()

            flash("new menu item %s created successfully!" % newItem.name)
            return redirect(url_for('showMenu', restaurant_id=restaurant_id))

    return render_template('new-menu-item.html', restaurant=restaurant, auth=True)
예제 #9
0
def newMenu(restaurant_id):
    rest = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if request.method == 'POST':
        myNewMenu = MenuItem(name=request.form['newName'],
                             course=request.form['newCourse'],
                             description=request.form['newDescription'],
                             price=request.form['newPrice'],
                             restaurant_id=restaurant_id)
        myNewCondition = Condition(name=request.form['newConditions'])
        session.add(myNewCondition)
        myNewMenu.conditions.append(myNewCondition)
        session.add(myNewMenu)
        session.commit()
        flash('New menu ' + myNewMenu.name + ' has been created!', 'message')
        return redirect(url_for('showMenus', restaurant_id=restaurant_id))
    else:
        if login_session.get('user_id') != rest.user_id:
            return redirect(url_for('showLogin'))
        return render_template('newMenuItem.html',
                               restaurant_id=restaurant_id,
                               restaurant=rest)
예제 #10
0
파일: __init__.py 프로젝트: xeispen/menuapp
def newMenuItem(restaurant_id):
    """ method to create new menu item """
    # Authorization to make sure user creating new menu-item created restaurant
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if restaurant.user_id != login_session['user_id']:
        flash('You are not authorized to create ' +
              'a menu-item for this restaurant.')
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           course=request.form['course'],
                           price=request.form['price'],
                           restaurant_id=restaurant_id,
                           user_id=login_session['user_id'])
        session.add(newItem)
        session.commit()
        flash("new menu item created!")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #11
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(
        id=restaurant_id).one()
    if request.method == 'POST':
        newItem = MenuItem(
            name=request.form['name'],
            restaurant_id=restaurant_id
        )
        session.add(newItem)
        session.commit()
        flash("New menu item: {name} created.".format(name=newItem.name))
        return redirect(url_for(
            'restaurantMenu',
            restaurant_id=restaurant_id
        ))
    else:
        return render_template(
            'newmenuitem.html',
            page_title="Create a new item for " + restaurant.name,
            restaurant=restaurant
        )
예제 #12
0
파일: project.py 프로젝트: Gendo90/OAuth2.0
def newMenuItem(restaurant_id):
    if ('user_id' in login_session):
        DBSession = sessionmaker(bind=engine)  #maybe wrong? ADDED
        session = DBSession()  #maybe wrong? ADDED
        restaurant = session.query(Restaurant).filter_by(
            id=restaurant_id).one()
        if request.method == 'POST':
            newItem = MenuItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               course=request.form['course'],
                               restaurant_id=restaurant_id)
            session.add(newItem)
            session.commit()
            flash('New Menu %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showMenu', restaurant_id=restaurant_id))
        else:
            return render_template('newmenuitem.html',
                                   restaurant_id=restaurant_id)
    else:
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
예제 #13
0
def newItem():
    catalogs = session.query(Catalog).all()
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        selectedCatalogDropdown = request.form.get('category')
        selectedCatalogId = str(selectedCatalogDropdown)
        selectedCatalog = session.query(Catalog).filter_by(
            id=int(selectedCatalogId)).one()

        newItem = MenuItem(user_id=login_session['user_id'],
                           name=request.form['name'],
                           description=request.form['description'],
                           price="", course="Item", catalog=selectedCatalog,
                           create_date=datetime.datetime.now())
        session.add(newItem)
        flash('New Item %s Successfully Created' % newItem.name)
        session.commit()
        return redirect(url_for('showCatalogs'))
    else:
        return render_template('newmenuitem.html', catalogs=catalogs)
예제 #14
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if ensureOwner(restaurant_id=restaurant_id):
        if request.method == 'POST':
            newItem = MenuItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               course=request.form['course'],
                               restaurant_id=restaurant_id,
                               user_id=restaurant.user_id)
            session.add(newItem)
            session.commit()
            flash("New menu Item " + newItem.name + " created!")
            return redirect(
                url_for('restaurantMenu', restaurant_id=restaurant_id))
        else:
            return render_template('newmenuitem.html',
                                   restaurant_id=restaurant_id)
    else:
        flash("You are not the owner of this restaurant")
        return redirect(url_for('showRestaurants'))
예제 #15
0
def addMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if request.method == 'POST':
        if request.form['name'] and request.form['price'] and \
        request.form['course'] and request.form['description']:
            newItem = MenuItem(name = request.form['name'],\
                               price = request.form['price'],\
                               course = request.form['course'],\
                               description = request.form['description'],
                               restaurant_id = restaurant_id)
            session.add(newItem)
            session.commit()
            flash('A new item has been added!')
            return redirect(url_for('menu', restaurant_id=restaurant_id))
        else:
            return 'empty value.'
    else:
        # courses = session.query(distinct(MenuItem.course)).filter_by(restaurant_id = restaurant_id).all()
        return render_template('addmenuitem.html',
                               restaurant=restaurant,
                               courses=courses)
예제 #16
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if request.method == 'POST':
        try:
            newItem = MenuItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               course=request.form['course'],
                               restaurant_id=restaurant_id,
                               user_id=restaurant.user_id)
            session.add(newItem)
            session.commit()
            flash('New Menu %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showMenu', restaurant_id=restaurant_id))
        except:
            flash('There was an error processing the request.\
                  Please fill all the details correctly.')
            return redirect(url_for('newMenuItem',
                                    restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #17
0
def newMenuItem(restaurant_id):

    #check authorization
    if 'username' not in login_session:
        flash('Must be logged in to add an item')
        return redirect('/login')

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           course=request.form['course'],
                           restaurant_id=restaurant_id,
                           user_id=login_session['user_id'])
        session.add(newItem)
        session.commit()
        #notify user
        flash('New menu item created')
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newMenuItem.html', restaurant_id=restaurant_id)
예제 #18
0
def newMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if login_session['user_id'] == restaurant.user_id:
        if request.method == 'POST':
            newItem = MenuItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               course=request.form['course'],
                               restaurant_id=restaurant_id,
                               user_id=restaurant.user_id)
            session.add(newItem)
            session.commit()
            flash('New Menu %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showMenu', restaurant_id=restaurant_id))
        else:
            return render_template('newmenuitem.html',
                                   restaurant_id=restaurant_id)
    else:
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
예제 #19
0
def newMenuItem(category_id):
    if 'username' not in login_session:
        return redirect('/login')
    category = session.query(Category).filter_by(id=category_id).one()
    if login_session['user_id'] != category.user_id:
        return
        "<script>function myFunction() " \
            "{alert('You are not authorized to add items to this category. " \
            "You must create your own category to add items.')}" \
            "</script><body onload='myFunction()''>"
    if request.method == 'POST':
        newItem = MenuItem(
                           name=request.form['name'],
                           description=request.form['description'],
                           category_id=category_id, user_id=category.user_id)
        session.add(newItem)
        session.commit()
        flash('New Item %s Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', category_id=category_id))
    else:
        return render_template('newmenuitem.html', category_id=category_id)
예제 #20
0
파일: project.py 프로젝트: czar3985/oauth
def newMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()

    if restaurant.user_id != login_session['user_id']:
        return "<script>function myFunction() {alert('You are not authorized to add menu items from this restaurant. You may only add to a restaurant you created.');}</script><body onload='myFunction()''>"

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           course=request.form['course'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        session.add(newItem)
        session.commit()
        flash('New Menu %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #21
0
def newMenuItem(item_id):
    if 'username' not in login_session:
        return redirect('/login')
    item = session.query(ItemType).filter_by(id=item_id).one()
    if login_session['user_id'] != item.user_id:
        return "<script>function myFunction() {alert('You are not authorized\
        to add menu items to this item. Please create your own item in order\
        to add items.');}</script><body onload='myFunction()''>"

        if request.method == 'POST':
            newItem = MenuItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               item_id=item_id,
                               user_id=item.user_id)
            session.add(newItem)
            session.commit()
            flash('New Menu %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showMenu', item_id=item_id))
    else:
        return render_template('newmenuitem.html', item_id=item_id)
예제 #22
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    owner = getUserInfo(restaurant.user_id)
    if owner.id != login_session['user_id']:
        flash('You do not have access to edit %s.' % restaurant.name)
        return redirect(url_for('showRestaurants'))
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'].strip(),
                           description=request.form['description'].strip(),
                           course=request.form['course'].strip(),
                           price=request.form['price'].strip(),
                           restaurant_id=restaurant.id)
        session.add(newItem)
        session.commit()
        flash('Menu item ' + '"' + newItem.name + '"' + ' created.')
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('_page.html',
                               title='New Menu Item',
                               view='newMenuItem',
                               restaurant=restaurant)
예제 #23
0
파일: project.py 프로젝트: kruuth/udacity
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if login_session['user_id'] != restaurant.user_id:
        return "<script>function myFunction()\
        {alert('You are not authorized to add menu items to this restaurant.\
        Please create your own restaurant in order to add items.');}</script>\
        <body onload='myFunction()'>"

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           course=request.form['course'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        session.add(newItem)
        session.commit()
        flash('New Menu %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #24
0
def AddMenuItemToRestaurant(restaurant_id):
    restaurant = getRestaurant(restaurant_id)
    if request.method == 'GET':
        return render_template('newmenuitem.html', restaurant=restaurant)
    else:
        newItem = MenuItem(name=request.form['newMenuItemName'])
        newItem.price = request.form['newMenuItemPrice']
        newItem.description = request.form['newMenuItemDescription']
        newItem.course = request.form['newMenuItemCourse']
        newItem.restaurant_id = restaurant.id
        session.add(newItem)
        session.commit()
        flash("New Menu Item Created: %s for Restaurant: %s" %
              (newItem.name, restaurant.name))
        return redirect(
            url_for('ListRestaurantMenu', restaurant_id=restaurant.id))
예제 #25
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).first()

    if not restaurant:
        return render_template(
            "404.html",
            msg='Restaurant {} doesn\'t exist'.format(restaurant_id)), 404
    else:
        if request.method == 'GET':
            return render_template("newmenuitem.html", restaurant=restaurant)
        elif request.method == 'POST':
            new_item = MenuItem(name=request.form['name'],
                                description=request.form['description'],
                                price=request.form['price'],
                                course=request.form['course'],
                                restaurant=restaurant)
            session.add(new_item)
            session.commit()

            flash('Menu Item Created')

            return redirect(url_for('showMenu', restaurant_id=restaurant_id))
예제 #26
0
def create_menu_item(restaurant_id):
    '''
    Gets the data from the form and creates a MenuItem object out of it and commit it 
    to the database. Flashes a message and redirects to the restaurant_menu function.
    Otherwise the createmenu.html is rendered given the restarant_id.
    '''
    if request.method == 'POST':
        new_menu_item = MenuItem(name=request.form['new_menu_item'],
                                 course=request.form['item_course'],
                                 description=request.form['item_desc'],
                                 price=request.form['item_price'],
                                 restaurant_id=restaurant_id)

        session.add(new_menu_item)
        session.commit()
        flash("New menu item: '" + str(new_menu_item.name) +
              "' has been created!")
        return redirect(url_for('restaurant_menu',
                                restaurant_id=restaurant_id))
    else:
        return render_template('createnewmenu.html',
                               restaurant_id=restaurant_id)
예제 #27
0
def newMenuItem(restaurant_id):

    if 'username' not in login_session:
        return redirect('/login')

    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if login_session['user_id'] != restaurant.user_id:
        return "<script>function myAlert() { alert('You are not authorized to add an item to this menu.'); }</script><body onload='myAlert()'>"
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           course=request.form['course'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        user_id = login_session['user_id']
        session.add(newItem)
        session.commit()
        flash('Menu Item "%s" Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #28
0
def newMenuItem(restaurant_id):
    if "username" not in login_session:
        return redirect(url_for("showLogin"))
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()

    # authorization check
    if restaurant.user_id != login_session['user_id']:
        flash("You are not authorized to change this menu.")
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           course=request.form['course'],
                           restaurant_id=restaurant_id)
        session.add(newItem)
        session.commit()
        flash('New Menu %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
def createMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if request.method == 'POST':
        if request.form['name']:
            name = request.form['name']
            description = request.form['description']
            price = request.form['price']
            course = request.form['course']
            item = MenuItem(name=name,
                            description=description,
                            price=price,
                            course=course,
                            restaurant_id=restaurant.id)
            session.add(item)
            session.commit()
            flash("New item menu created!")
            return redirect(
                url_for('readRestaurant', restaurant_id=restaurant.id))
        else:
            return "ERROR"
    else:
        return render_template('createMenuItem.html', restaurant=restaurant)
예제 #30
0
def itemAdd():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        if request.form['NewItem']:
            NewItem = MenuItem(name=request.form['NewItem'],
                               user_id=login_session['user_id'],
                               category_id=request.form['categoryid'],
                               description=request.form['desc'])
            session.add(NewItem)
            session.commit()
            return redirect(url_for('categoryMenu'))
        else:
            return "Name field cannot be empty"
    else:
        # defining categories to get all categories
        # avaialble then add it to
        # Option Select in HTML
        categories = session.query(Category).all()
        return render_template("newitem.html",
                               categories=categories,
                               login_session=login_session)
예제 #31
0
def new_menu_item(restaurant_id):

    try:

        session = DBSession()

        restaurant = session.query(Restaurant).filter_by(
            id=restaurant_id).one()
        if restaurant is None:
            return render_template("404.html"), 404

        if request.method == "GET":
            return render_template("newmenuitem.html",
                                   restaurant_id=restaurant_id)

        if request.method == "POST":
            item_name = request.form["name"]
            if not item_name or not item_name.strip():
                flash("Menu item name is required!")
                return render_template("newmenuitem.html",
                                       restaurant_id=restaurant_id)

            new_item = MenuItem(name=item_name,
                                course=request.form["course"],
                                description=request.form["description"],
                                price=request.form["price"],
                                restaurant_id=restaurant_id)
            session.add(new_item)
            session.commit()

            flash("Menu item created successfully!")

        return redirect(url_for("restaurant_menu",
                                restaurant_id=restaurant_id))

    finally:

        if session:
            session.close()
예제 #32
0
def newMenu(restaurant_id):
    if request.method == 'POST':
        item = MenuItem(name=request.form['name'],
                        course=request.form['course'],
                        price=request.form['price'],
                        description=request.form['description'],
                        restaurant_id=restaurant_id)
        session.add(item)
        session.commit()
        # items.append({'name': request.form['name'], 'id': 100, 'course': request.form['course'],
        #               'price': request.form['price'], 'description': request.form['description']})
        flash('Menu: %s created' % request.form['name'])
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        restaurant_name = session.query(Restaurant).filter_by(
            id=restaurant_id).one()
        # for restaurant in restaurants:
        #     if int(restaurant['id']) == restaurant_id:
        #         restaurant_name = restaurant['name']
        return render_template('newMenu.html',
                               restaurant_name=restaurant_name.name,
                               restaurant_id=restaurant_id)
예제 #33
0
def newMenuItem(restaurant_id):
    """
    allows users to add a new menu to a restaurant
    """
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if 'email' not in login_session:
        return redirect(url_for('showRestaurants'))
    if login_session['email'] != restaurant.user_email:
        return redirect(url_for('showRestaurants'))
    if request.method == 'POST':
        newItem = MenuItem(
            name=request.form['name'],
            description=request.form['description'],
            price=request.form['price'],
            course=request.form['course'],
            restaurant_id=restaurant_id)
        session.add(newItem)
        session.commit()
        flash('New Menu %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #34
0
def addMenuItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'GET':
        sqlalchemy_obj = session.query(Restaurant).filter_by(id=restaurant_id)
        if sqlalchemy_obj.count() == 0:
            flash('No menu available for this restaurant')
            return redirect(url_for('restaurantsList'))
        restaurant = sqlalchemy_obj.one()
        return render_template('newMenuItem.html', restaurant=restaurant)
    else:
        sqlalchemy_obj = session.query(Restaurant).filter_by(id=restaurant_id)
        if sqlalchemy_obj.count() == 0:
            flash('No menu available for this restaurant')
            return redirect(
                url_for('restaurantMenu', restaurant_id=restaurant_id))
        else:
            restaurant = sqlalchemy_obj.one()
        form = request.form
        if len(form) > 0 and 'name' in form:
            menu_name = form['name']
        else:
            flash('Cannot add the menu item to menu')
            return redirect(
                url_for('restaurantMenu', restaurant_id=restaurant_id))
        description = form['description'] if 'description' in form else None
        price = '$' + str(form['price']) if 'price' in form else None
        course = form['course'] if 'course' in form else None
        menu_item = MenuItem(name=menu_name,
                             description=description,
                             price=price,
                             course=course,
                             restaurant_id=restaurant_id,
                             user_id=restaurant.user_id)
        session.add(menu_item)
        session.commit()
        flash('Added the menu item to the menu')
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
예제 #35
0
def newMenuItem(restaurant_id):
    """Render a view for creating a new menu item"""
    restaurant = session.query(Restaurant).filter_by(
        id=restaurant_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    if restaurant.user_id != login_session['user_id']:
        return ('Your are not authorized to add items to this restaurant. '
                'Please create your own restaurant to add menu items.')
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           course=request.form['course'],
                           description=request.form['description'],
                           price=request.form['price'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        session.add(newItem)
        session.commit()
        flash("New menu item created!", "success")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #36
0
def newMenuItem(restaurant_id):

    if 'username' not in login_session:
        return redirect('/login')

    real_restaurant = session.query(Restaurant).filter_by(
        id=restaurant_id).one()

    if request.method == 'POST':

        newItem = MenuItem(name=request.form['name'],
                           restaurant_id=restaurant_id,
                           user_id=real_restaurant.user_id)
        session.add(newItem)
        session.commit()

        flash('new menu item created')

        return redirect(url_for('showMenu', restaurant_id=restaurant_id))

    else:
        return render_template('newMenuItem.html', restaurant=real_restaurant)
예제 #37
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    # Alerts users that they don't have permission to add menu items if they aren't the creator of the restaurant
    if restaurant.user_id != login_session['user_id']:
        return "<script>function dontHavePermission() {alert('You are not authorized to add menu items to this restaurant. Please create your own.');}</script><body\
                onload='dontHavePermission()'>"

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           course=request.form['course'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        session.add(newItem)
        session.commit()
        flash('New Menu %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
예제 #38
0
def newMenuItem(restaurant_id):
    restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
    if restaurant.user_id != login_session.get('user_id'):
        return "<script>function myFunction() {alert('You are not authorized to \
        add new item to this restaurant. Please create your own restaurant in \
        order to edit.');location.replace(history.back());}</script><body \
        onload='myFunction()''>"

    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           price=request.form['price'],
                           description=request.form['description'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        session.add(newItem)
        session.commit()
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newitem.html',
                               uname=login_session['username'],
                               restaurant_id=restaurant_id,
                               restaurant=restaurant)
def newMenuItem(restaurant_id):
	restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
	if request.method == 'POST':
		price = re.search(r'\$\d+\.\d\d', request.form['newItemPrice'])
		if (len(request.form['newItemName']) > 0 and len(request.form['newItemPrice']) > 0 and
			price):
			newItem = MenuItem() 
			newItem.name = request.form['newItemName']
			newItem.description = request.form['newItemDescription']
			newItem.price = request.form['newItemPrice']
			newItem.course = request.form['newItemCourse']
			newItem.restaurant_id = restaurant.id
			session.add(newItem)
			session.commit()
			flash('New menu item created!')
			return redirect(url_for('showMenu', restaurant_id=restaurant_id))
		else:
			flash('Make sure you add a valid new menu item name and valid price when creating a new item')
			return redirect(url_for('showMenu', restaurant_id=restaurant_id))
	else:
		return render_template('addmenuitem.html', restaurant=restaurant)
def AddMenuItem():
    restaurants = session.query(Restaurant).all()
    new_item = MenuItem()
    if request.method == 'GET':
        return render_template('newMenuItem.html', restaurants=restaurants)
        
    elif request.method == 'POST':
        if request.form['name']:
            new_item.name = request.form['name']
        if request.form['course']:
            new_item.course = request.form['course']
        if request.form['description']:
            new_item.description = request.form['description']
        if request.form['price']:
            new_item.price = request.form['price']
        if request.form['restaurant_id']:
            new_item.restaurant_id = request.form['restaurant_id']    
        
        session.add(new_item)
        session.commit()
        flash('New Item created!')
        return redirect(url_for('index'))