Ejemplo n.º 1
0
def newMenuItem(restaurant_id):
    """Create new menu entry."""
    if 'username' not in login_session:
        return redirect('/login')
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    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'],
                           restaurant_id=restaurant_id,
                           user_id=restaurant.user_id)
        session.add(newItem)
        session.commit()
        flash('New menu item created!')
        return redirect(url_for('showMenu', restaurant_id=restaurant_id),
                        code=301)
    elif request.method == 'GET':
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
    else:
        return redirect(url_for('showMenu', restaurant_id=restaurant_id),
                        code=301)
Ejemplo n.º 2
0
def AddMenu(rest_id):
    if request.method == 'POST':
        new_menu_item = MenuItem(name=request.form['name'],
                                 restaurant_id=rest_id)
        session.add(new_menu_item)
        session.commit()
        return redirect(url_for('ViewMenus', rest_id=rest_id))
    else:
        return render_template('newmenuitem.html', rest_id=rest_id)
Ejemplo n.º 3
0
def newMenuItem(restaurant_id):
    if request.method=='POST':
        newItem = MenuItem(name=request.form['name'],restaurant_id=restaurant_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)
Ejemplo n.º 4
0
def newMenuItem(catalog_id):
    if request.method == 'POST':
        newItem = MenuItem(name=request.form['name'],
                           description=request.form['description'],
                           catalog_id=catalog_id)
        session.add(newItem)
        session.commit()

        return redirect(url_for('showMenu', catalog_id=catalog_id))
    else:
        return render_template('newmenuitem.html', catalog_id=catalog_id)

    return render_template('newMenuItem.html')
Ejemplo n.º 5
0
def addMenuItem(restaurant_id):
    # return "New menu item to be added"
    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()
        return redirect(url_for('displayMenuItem',
                                restaurant_id=restaurant_id))
    else:
        return render_template('newMenuItem.html', restaurant_id=restaurant_id)
Ejemplo n.º 6
0
def newmenu(restaurant_id):
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    session = start()

    if request.method == 'POST':
        menuitem = MenuItem(name=str(request.form['name']).title(),
                            price=request.form['price'],
                            description=request.form['description'],
                            course=request.form['course'],
                            restaurant_id=restaurant_id)
        session.add(menuitem)
        session.commit()
        close(session)
        return redirect(url_for('menu', restaurant_id=restaurant_id))

    close(session)
    return render_template('newmenu.html', restaurant_id=restaurant_id)
Ejemplo n.º 7
0
def newMenuItem(bar_id):
    if 'username' not in login_session:
        return redirect('/login')
    bar = session.query(Bar).filter_by(id=bar_id).one()
    if login_session['user_id'] != bar.user_id:
        return "<script>function myFunction() {alert('You are not authorized to add menu items to this bar. Please create your own bar 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'],
                               bar_id=bar_id,
                               user_id=bar.user_id)
            session.add(newItem)
            session.commit()
            flash('New Menu %s Item Successfully Created' % (newItem.name))
            return redirect(url_for('showMenu', bar_id=bar_id))
    else:
        return render_template('newMenuItem.html', bar_id=bar_id)
Ejemplo n.º 8
0
# this makes connections bt class definitions and corresponding tables
Base.metadata.bind = engine

# establish connection between code executions and created engine
# allows preparation of many commands before `committing` to database
DBSession = sessionmaker(bind=engine)

# create a singular session to execute some code
# this session will act as a staging ground - none of the changes
# made within the session will persist unless session.commit is called
session = DBSession()

# creating an entry in db is easy as creating a new python object
firstRestaurant = Restaurant(name='Pizza Palace')

# the new object must be added to the current session
session.add(firstRestaurant)

# to save the changes in session we must commit
session.commit()

cheesepizza = MenuItem(
    name='Cheese Pizza',
    description='Made with all natural ingredients and fresh mozzarella',
    course='Entree',
    price='$8.99',
    restaurant=firstRestaurant)

session.add(cheesepizza)
session.commit()
    picture=
    'https://lh3.googleusercontent.com/-rs3jvXJp8_A/UYZspNGV60I/AAAAAAAAACQ/liJmb97XHcQ/w139-h140-p/DSC08783.JPG'
)
session.add(User2)
session.commit()

# Menu for UrbanBurger
restaurant1 = Restaurant(user_id=2, name="Urban Burger")

session.add(restaurant1)
session.commit()

menuItem2 = MenuItem(
    user_id=2,
    name="Veggie Burger",
    description="Juicy grilled veggie patty with tomato mayo and lettuce",
    price="$7.50",
    course="Entree",
    restaurant=restaurant1)

session.add(menuItem2)
session.commit()

menuItem1 = MenuItem(user_id=2,
                     name="French Fries",
                     description="with garlic and parmesan",
                     price="$2.99",
                     course="Appetizer",
                     restaurant=restaurant1)

session.add(menuItem1)
Ejemplo n.º 10
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()


#categories items
# catalog1
catalog1 = Catalog(name="Football")

session.add(catalog1)
session.commit()

menuItem1 = MenuItem(name="ball", description="The Ball is important for play football",
                        catalog=catalog1)

session.add(menuItem1)
session.commit()


# catalog2
catalog2 = Catalog(name="Basketball")

session.add(catalog2)
session.commit()

menuItem2 = MenuItem(name="Basket", description="The players will use the Basket for goals",
                        catalog=catalog2)

session.add(menuItem2)
Ejemplo n.º 11
0
# Create dummy user
User1 = User(name="Joe Cool ",
             email="*****@*****.**",
             picture='https://bit.ly/2ZHVb2a')
session.add(User1)
session.commit()

# Menu for UrbanBurger
bar1 = Bar(user_id=1, name="Urban Burger")

session.add(bar1)
session.commit()

menuItem2 = MenuItem(user_id=1,
                     name="beyond Burger",
                     description="mimi yummy",
                     price="$7.50",
                     course="Entree",
                     bar=bar1)

session.add(menuItem2)
session.commit()

menuItem1 = MenuItem(user_id=1,
                     name="Fries",
                     description="with garlic and parmesan",
                     price="$2.99",
                     course="Appetizer",
                     bar=bar1)

session.add(menuItem1)
session.commit()
Ejemplo n.º 12
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from db_setup import Base, Restaurant, MenuItem

# interates with database engine
engine = create_engine('sqlite:///restaurant.db')

Base.metadata.bind = engine  # binding the tables
DbSession = sessionmaker(bind=engine)
session = DbSession()

firstRes = Restaurant(name="Pizza hut")
session.add(firstRes)
session.commit()

cheezePizza = MenuItem(name="Cheeze Pizza", description="Made with natural ingredients and fresh mozzarella",
                       course="Entree", price="$8.99", restaurant=firstRes)
session.add(cheezePizza)
session.commit()

print(session.query(Restaurant).all())
print(session.query(MenuItem).all())