Exemplo n.º 1
0
def add():
    foods = None
    if request.form:
        try:
            food = FoodItem(name=request.form.get("title"),
                            calories=request.form.get("calories"),
                            fat_cals=request.form.get("fat_cals"),
                            total_fat=request.form.get("total_fat"),
                            saturated_fat=request.form.get("saturated_fat"),
                            trans_fat=request.form.get("trans_fat"),
                            cholesterol=request.form.get("cholesterol"),
                            sodium=request.form.get("sodium"),
                            carbohydrates=request.form.get("carbohydrates"),
                            dietary_fiber=request.form.get("dietary_fiber"),
                            sugars=request.form.get("sugars"),
                            protein=request.form.get("protein"),
                            vitamin_a=request.form.get("vitamin_a"),
                            vitamin_c=request.form.get("vitamin_c"),
                            calcium=request.form.get("calcium"),
                            iron=request.form.get("iron"))
            session.add(food)
            session.commit()
        except Exception as e:
            print("Failed to add food item.")
            print(e)
    return home()
Exemplo n.º 2
0
def add_new_food_item(food_group_id, difficulty):
    """Adds new food item to food group at given difficulty"""

    session = DBSession()

    if request.method == 'POST' and login_session['username'] is not None:
        name = request.form['name']
        description = request.form['description']
        recipe = request.form['recipe']
        new_item = FoodItem(name=name,
                            difficulty=difficulty,
                            description=description,
                            recipe=recipe,
                            food_group_id=food_group_id,
                            creator_email=login_session['email'])
        session.add(new_item)
        session.commit()
        flash('Item added')
        return redirect(
            url_for('show_food_group',
                    food_group_id=food_group_id,
                    difficulty=difficulty))

    # Display input form for new item
    else:
        food_group = (session.query(FoodGroup).filter_by(
            id=food_group_id).one())
        return render_template('add_new_food_item.html',
                               food_group=food_group,
                               difficulty=difficulty)
Exemplo n.º 3
0
def newFoodItem(foodgroup_id):
    foodgroup = session.query(FoodGroup).filter_by(id=foodgroup_id).one()
    creator = getUserInfo(foodgroup.user_id)
    if 'username' not in login_session or \
            creator.id != login_session['user_id']:
        return render_template('accessdenied.html')
    if 'username' not in login_session:
        return redirect('/login')
    foodgroup = session.query(FoodGroup).filter_by(id=foodgroup_id).one()
    if request.method == 'POST':
        newItem = FoodItem(name=request.form['name'],
                           foodgroup_id=foodgroup_id)
        if request.form['name']:
            newItem.name = request.form['name']
        if request.form['calories']:
            newItem.calories = request.form['calories']
        if request.form['carbs']:
            newItem.carbs = request.form['carbs']
        if request.form['sugars']:
            newItem.sugars = request.form['sugars']
        if request.form['fats']:
            newItem.fats = request.form['fats']
        session.add(newItem)
        session.commit()
        flash('New Food %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showFoodItem', foodgroup_id=foodgroup_id))
    else:
        return render_template('newFoodItem.html', foodgroup_id=foodgroup_id)
Exemplo n.º 4
0
def addFoodItem(cuisine_id):
    user_id = getUserID(login_session.get('email'))
    if not user_id:
        return redirect(url_for('showItems', cuisine_id=cuisine_id))
    if request.method == 'POST':
        foodItem = FoodItem(user_id=user_id,
                            description=request.form['description'],
                            name=request.form['name'],
                            ingredient=request.form['ingredient'],
                            cuisine_id=cuisine_id)
        session.add(foodItem)
        session.commit()
        flash("A food item added to Cuisine")
        return redirect(url_for('showItems', cuisine_id=cuisine_id))
    else:
        return render_template('addfooditem.html')
Exemplo n.º 5
0
def newFoodItem(restaurant_id):
    if 'username' not in login_session:
        return redirect('/login')

        session = connect_to_database()

    if request.method == 'POST':
        newItem = FoodItem(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           restaurant_id=restaurant_id)
        session.add(newItem)
        session.commit()
        flash("Menu Item has been added")
        return redirect(url_for('restaurantMenu', restaurant_id=restaurant_id))
    else:
        return render_template('newmenuitem.html', restaurant_id=restaurant_id)
    return render_template('newMenuItem.html', restaurant=restaurant)
Exemplo n.º 6
0
def addFoodItem():

    if request.method == 'POST':

        if not request.form['name']:
            flash('Please enter name')
            return redirect(url_for('addFoodItem'))

        if not request.form['fid']:
            flash('Please enter Food ID')
            return redirect(url_for('addFoodItem'))

        if not request.form['cfid']:
            flash('Please enter category ID')
            return redirect(url_for('addFoodItem'))

        if not request.form['price']:
            flash('Please enter price')
            return redirect(url_for('addFoodItem'))
        if not request.form['description']:
            flash('Please enter description')
            return redirect(url_for('addFoodItem'))
        if not request.form['stsid']:
            flash('Please enter status id')
            return redirect(url_for('addFoodItem'))

        # Add new item
        newFoodItem = FoodItem(fid=request.form['fid'],
                               name=request.form['name'],
                               cfid=request.form['cfid'],
                               price=request.form['price'],
                               description=request.form['description'],
                               stsid=request.form['stsid'])
        session.add(newFoodItem)
        session.commit()

        return redirect(url_for('showRestaurantMenu'))
    else:
        # Get all categories
        foodcategories = session.query(FoodCategory).all()
        return render_template('addFoodItem.html',
                               foodcategories=foodcategories)
Exemplo n.º 7
0
def showFood(course_id):
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        course = session.query(Course).filter_by(id=course_id).one()
        user = session.query(UserTable).filter_by(
            email=login_session['email']).one()
        newItem = FoodItem(name=request.form['newFoodName'],
                           description=request.form['newFoodDescription'],
                           course_id=course_id,
                           user_id=user.id)
        session.add(newItem)
        session.commit()
        # flash('New Menu %s Item Successfully Created' % (newItem.name))
        # return redirect(url_for('showFood', course_id=course_id))
    courses = session.query(Course).order_by(asc(Course.name))
    course = session.query(Course).filter_by(id=course_id).one()
    food = session.query(FoodItem).filter_by(course_id=course_id).all()
    return render_template('food.html',
                           food=food,
                           course=course,
                           courses=courses)
Exemplo n.º 8
0
def newFoodItem(foodclass_id):
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':
        foodclass = session.query(FoodClass).filter_by(id=foodclass_id).one()
        # careful to only insert returns that actually have a name to it
        if request.form['name']:
            newItem = FoodItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               typical_size=request.form['typical_size'],
                               need_to_shop=0,
                               foodclass=foodclass,
                               creator_id=login_session['user_id'])
            session.add(newItem)
            session.commit()
            flash("Food item {} was successfully created".format(
                request.form['name']))
        return redirect(url_for('SingleFoodClass', foodclass_id=foodclass_id))
    else:
        return render_template('newFoodItem.html',
                               foodclass_id=foodclass_id,
                               uname=getUserName())
Exemplo n.º 9
0
             picture='''https://pbs.twimg.com/profile_images/
        2671170543/18debd694829ed78203a5a36dd364160_400x400.png''',
             password='******')
session.add(User1)
session.commit()

# Menu for UrbanBurger

cuisine1 = Cuisine(user_id=1, name='American')

session.add(cuisine1)
session.commit()

foodItem2 = FoodItem(user_id=1,
                     name='Veggie Burger',
                     description='''Juicy grilled veggie patty
                     with tomato mayo and lettuce''',
                     ingredient='veggie patty,tomato',
                     cuisine=cuisine1)

session.add(foodItem2)
session.commit()

foodItem1 = FoodItem(user_id=1,
                     name='French Fries',
                     description='with garlic and parmesan',
                     ingredient='gralic, parmesan',
                     cuisine=cuisine1)

session.add(foodItem1)
session.commit()
Exemplo n.º 10
0
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Establishing Meals
course1 = Course(name="Breakfast")
session.add(course1)
session.commit()

food1 = FoodItem(name="Pancakes",
                 description="A fluffy circular sweet bread.",
                 course=course1)

session.add(food1)
session.commit()

course2 = Course(name="Lunch")
session.add(course2)
session.commit()

food2 = FoodItem(name="Chicken sandwich",
                 description="chicken with bread, lettuce, and tomato",
                 course=course2)
session.add(food2)
session.commit()
Exemplo n.º 11
0
                         stsid='S1')  #change.....................

session.add(foodcat1)
session.add(foodcat2)
session.add(foodcat3)
session.add(foodcat4)
session.add(foodcat5)
session.add(foodcat6)
session.add(foodcat7)
session.add(foodcat8)
session.add(foodcat9)  #change.....................
session.add(foodcat10)  #change.....................

foodit1 = FoodItem(fid='1',
                   name='ORANGE',
                   cfid='FC1',
                   price=7,
                   description='',
                   stsid='S1')
foodit2 = FoodItem(fid='2',
                   name='MANGO',
                   cfid='FC1',
                   price=7,
                   description='',
                   stsid='S1')
foodit3 = FoodItem(fid='3',
                   name='LEMON',
                   cfid='FC1',
                   price=7,
                   description='',
                   stsid='S1')
foodit4 = FoodItem(fid='4',
Exemplo n.º 12
0
session.add(restaurant1)
session.commit()

restaurant2 = Restaurant(name="Suprabhath Multi cuisine")

session.add(restaurant2)
session.commit()

restaurant3 = Restaurant(name="Chandrika")

session.add(restaurant3)
session.commit()

menuItem1 = FoodItem(name="Masala Dosa",
                     description="Crepe made from rice"
                     "batter and black lentils.",
                     price="$2.99", restaurant=restaurant1, user_id=1)

session.add(menuItem1)
session.commit()

menuItem2 = FoodItem(name="Sambar Idly",
                     description=" Rice cake with"
                     "lentil-based vegetable stew.",
                     price="$7.50",  restaurant=restaurant1, user_id=1)

session.add(menuItem2)
session.commit()


menuItem3 = FoodItem(name="Pongal",
Exemplo n.º 13
0
session = DBSession()


# Create dummy user
User1 = User(name="Robo Barista", email="*****@*****.**",
             picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png')
session.add(User1)
session.commit()

# Items in Grains food group
Grains = FoodGroup(user_id=1, name="Grains")

session.add(Grains)
session.commit()

foodItem1 = FoodItem(user_id=1, name="Wheat Bread",
                     carbs="25", sugars="0", fats="0", calories="120", foodGroup=Grains)

session.add(foodItem1)
session.commit()

foodItem2 = FoodItem(user_id=1, name="White Rice",
                     carbs="80", sugars="0", fats="1", calories="360", foodGroup=Grains)

session.add(foodItem2)
session.commit()

foodItem3 = FoodItem(user_id=1, name="Tortilla",
                     carbs="23", sugars="0", fats="4", calories="140", foodGroup=Grains)

session.add(foodItem3)
session.commit()
Exemplo n.º 14
0
session.commit()

#Items for grains
foodclass1 = FoodClass(name = "Grains & grain products")

session.add(foodclass1)
session.commit()

for [name, description, price, typical_size] in [["Wheat Flour T550", "Wheat flour of the type 550", "2.55", '1 kg'],
                                                 ["Rye Flour T1150", "Rye flour of the type 1150, used for bread", "2.95", '1 kg'],
                                                 ["Rice", "polished rice", '1.99', '250 g'],
                                                 ['Popcorn-Mais', 'dried grains of popcorn mais', '3.50', '250 g'],
                                                 ['Spirelli', 'Spirelli noodles Nr. 32', '1.50', '250 g']]:


    foodItem1 = FoodItem(name = name, description = description, price = price, typical_size = typical_size, need_to_shop = 0, foodclass = foodclass1, creator = user1)

    session.add(foodItem1)
    session.commit()

#Items for milk products
foodclass2 = FoodClass(name = "Milk products")

session.add(foodclass2)
session.commit()

for [name, description, price, typical_size] in [["H-Milk", "H-Milk with 3,5% fat", "1.95", '1 litre'],
                                                 ["Cream", "Sweet Cream with > 30% fat", "2.95", '250 ml'],
                                                 ["Joghurt", "natural joghurt with 3,5% fat", '0.39', '125 ml'],
                                                 ['Parmesan', 'Dry well aged cheese from Parma region', '2.50', '100 g'],
                                                 ['Gorgonzola', 'blue cheese from some caves in France...', '2.80', '100 g']]: