def __init__(self):
        '''Creates entities to populate the mock database.
        '''
        self.mock_users = (User('A', '*****@*****.**'), User('B', '*****@*****.**'),
                           User('C', '*****@*****.**'))

        self.pantries = [
            Pantry('Pantry_A', 1),
            Pantry('Pantry_B', 2),
            Pantry('Pantry_C', 3),
            Pantry('Pantry_D', 1)
        ]

        self.categories = [
            Category('vegetables', 1),
            Category('starches', 1),
            Category('desserts', 1),
            Category('veggies', 2),
            Category('snacks', 2),
            Category('meat', 2),
            Category('fruit', 3),  # 7
            Category('meat', 3),
            Category('drinks', 3)
        ]

        self.items = [
            Item('apple', 'shiny and red', 5, 1, 1),  # 0
            Item('broccoli', 'small tree', 10, 5, 1),  # 1
            Item('chips', 'crispy', 4, 5, 5),  # 2
            Item('steak', 'high in protein', 1, 20, 8),
            Item('seltzer', 'fizzy', 15, 1, 3),
            Item('cake', 'moist', 1, 15, 3),
            Item('potato', 'high in carbs', 50, 20, 2),
            Item('apple', 'shiny and red', 5, 1, 7)
        ]
Exemplo n.º 2
0
def newCategory():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newCategory = Category(name=request.form['name'],
                               user_id=login_session['user_id'])
        session.add(newCategory)
        flash('New Category %s Successfully Created' % newCategory.name)
        session.commit()
        return redirect(url_for('showCategories'))
    else:
        return render_template('newcategory.html')
#!/usr/bin/env python3

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from catalog_database_setup import Category, Item, Base

engine = create_engine('postgresql://*****:*****@localhost/grader')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()


categories = ['Soccer', 'Basketball', 'Baseball', 'Frisbee', 'Snowboarding',
              'Rock Climbing', 'Football', 'Skating', 'Hockey']

for category in categories:
    session.add(Category(name=category))
    session.commit()

print("all the categories have been added to the database")
Exemplo n.º 4
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()

session.query(Item).delete()
session.commit()

session.query(Category).delete()
session.commit()

Fashion = Category(name="Fashion")

session.add(Fashion)
session.commit()

Travel = Category(name="Travel Essentials")

session.add(Travel)
session.commit()

Music = Category(name="Music")

session.add(Music)
session.commit()

Electronics = Category(name="Electronics")
Exemplo n.º 5
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from catalog_database_setup import Base, Category, Item
engine = create_engine('sqlite:///catalog.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

soccer = Category(name='Soccer')
session.add(soccer)

basketball = Category(name='Basketball')
session.add(basketball)

baseball = Category(name='Baseball')
session.add(baseball)

frisbee = Category(name='Frisbee')
session.add(frisbee)

snowBoarding = Category(name='Snowboarding')
session.add(snowBoarding)

rock_climbing = Category(name='Rock Climbing')
session.add(rock_climbing)

foosball = Category(name='Foosball')
session.add(foosball)

skating = Category(name='Skating')
session.add(skating)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from catalog_database_setup import Base, Category, Item
from random import randint

url = 'postgresql://{}:{}@{}:{}/{}'
url = url.format('catalog', 'password', 'localhost', '5432', 'catalog_db')
engine = create_engine(url, client_encoding='utf8')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

category = Category(name="Apps & Games")
session.add(category)
item = Item(name="Tetris",
            description="Description of Tetris",
            category=category)
session.add(item)
item = Item(name="Minecraft",
            description="Description of Minecraft",
            category=category)
session.add(item)
item = Item(name="Hungry Shark Evolution",
            description="Description of Hungry Shark Evolution",
            category=category)
session.add(item)
item = Item(name="Portal",
            description="Description of Portal",
            category=category)
Exemplo n.º 7
0
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
user1 = User(
    name="Amhar Ford",
    email="*****@*****.**",
    picture=
    'https://lh5.googleusercontent.com/-fEdEA2m4s20/AAAAAAAAAAI/AAAAAAAAEXY/wJ66AgeAHLQ/photo.jpg'
)
session.add(user1)
session.commit()

#Category for Dairy
category1 = Category(name="Dairy", user=user1)

session.add(category1)
session.commit()

groceryItem1 = GroceryItem(name="cheese",
                           description="Cheese is a food \
			derived from milk that is produced in a wide range of flavors, \
			textures, and forms by coagulation of the milk protein casein. It\
			 comprises proteins and fat from cow's milk.",
                           price="$3.20",
                           item_image="/static/cheese.jpg",
                           category=category1,
                           user=user1)

session.add(groceryItem1)
# Users
user1 = User(name="Phoenix Daphne", email="*****@*****.**")
session.add(user1)
session.commit()

user2 = User(name="Sonny Tilander", email="*****@*****.**")
session.add(user1)
session.commit()

user3 = User(name="Hugh Altretch", email="*****@*****.**")
session.add(user1)
session.commit()

# Category 'Soccer'
category1 = Category(name="Soccer")
session.add(category1)
session.commit()

item1 = Item(name="Pair of Shin Guards",
             description=("Description: Black pair of shin guards. "
                          "Made of foam rubber. Light and sturdy."),
             category=category1,
             user=user1)
session.add(item1)
session.commit()

item2 = Item(name="Soccer Jersey of Leeds",
             description=("Description: White jersey with blue logo on. "
                          "Made of cotton. Machine-fitted."),
             category=category1,
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# 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()

#Category Load
category1 = Category(name="Basketball")

session.add(category1)

category2 = Category(name="Football")

session.add(category2)

category3 = Category(name="Softball")

session.add(category3)

category4 = Category(name="Skiing")

session.add(category4)
Exemplo n.º 10
0
# 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()

# Create dummy user

User1 = User(name="Rafaela Cavalcante",
             email="*****@*****.**",
             picture='https://pbs.twimg.com/profile_images/2671170543/'
             '18debd694829ed78203a5a36dd364160_400x400.png')
session.add(User1)
session.commit()

# Items for Kitchen
category1 = Category(user_id=1, name="Kitchen")

session.add(category1)
session.commit()

houseItem1 = HouseItem(user_id=1,
                       name="Freezer",
                       description=" Brastemp Freezer inverted position 2015.",
                       price="$2,500",
                       status="for sale",
                       category=category1)

session.add(houseItem1)
session.commit()

houseItem2 = HouseItem(user_id=1,