Ejemplo n.º 1
0
def createUser(login_session):
    newUser = Users(email=login_session[
        'email'], picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(Users).filter_by(email=login_session['email']).one()
    return user.id
Ejemplo n.º 2
0
def createUser(login_session):
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    new_user = Users(name=login_session['username'], email=login_session[
        'email'])
    session.add(new_user)
    session.commit()
    user = session.query(Users).filter_by(email=login_session['email']).one()
    return user.id
Ejemplo n.º 3
0
def createUser(login_session):
    '''
    this function creates new user information
    session.add() is add the user
    session.commit() is commit the session
    '''
    user = Users(name=login_session['username'],
                 email=login_session['email'],
                 picture=login_session['picture'])
    session.add(user)
    session.commit()
    user_db = session.query(Users).filter_by(
        email=login_session['email']).one()
    return user_db.id
Ejemplo n.º 4
0
def userPage(user_id):
    if request.args.get('local') == 'true':
        return jsonify(
            session.query(Users).filter_by(id=user_id).one().serialize)
    user = getUser(user_id)
    tmp = session.query(Users).filter_by(id=user_id).first()
    if tmp:
        tmp.name = user['name']
        tmp.id = user['id']
    else:
        tmp = Users(name=user['name'], id=user['id'])
    session.add(tmp)
    session.commit()
    return jsonify(tmp.serialize)
Ejemplo n.º 5
0
def createUser(login_session):
    """ If a user logs in for the first time, create their user in the DB

        Args:
            login_sesion:  Login session object
        Returns
            user.id:  Integer:  The primary key of the user
    """

    newUser = Users(name=login_session['username'],
                    email=login_session['email'],
                    picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(Users).filter_by(email=login_session['email']).one()
    return user.id
Ejemplo n.º 6
0
def createUser(login_session):
    # Method for adding a new user to the DB
    #
    # Args:
    #   login_session - this is a list that contains all of login
    #   information of the logged in user.
    #
    # Returns:
    #   User.id - this is the DB generated id once the user has been added to
    #   the DB.

    newUser = Users(name=login_session['name'], email=login_session[
                   'email'], picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(Users).filter_by(email=login_session['email']).one()
    return user.id
Ejemplo n.º 7
0
# Delete all items in Beers table
allBeers = session.query(Beer).all()
for beer in allBeers:
    session.delete(beer)
    session.commit()

# Delete all items in the Users table
allUsers = session.query(Users).all()
for users in allUsers:
    session.delete(users)
    session.commit()

originalUser = Users(
    name='Preston Doris',
    email='*****@*****.**',
    picture=
    'https://lh4.googleusercontent.com/-Hs9d2xbVGlA/AAAAAAAAAAI/AAAAAAAAAFw/CO3e-KX2o5Y/photo.jpg'
)
session.add(originalUser)
session.commit()

# Add Breweries to the DB
# Brewery 1
brewery1 = Brewery(name='21st Amendment Brewery', user_id=1)
session.add(brewery1)
session.commit()
# Brewery 1 Beers
b1beer1 = Beer(
    name='Brew Free! or Die IPA',
    description='''BREW FREE! OR DIE IPA is brewed with some serious west
        coast attitude. This aromatic golden IPA starts with three different

# Load Categories into database

for i in master_list:
    category = Category(user_id=1, name=i[0])
    item1 = Item(user_id=1,
                 name=i[1],
                 desc=i[2],
                 dateadded=CreateRandomDate(),
                 category=category)
    item2 = Item(user_id=1,
                 name=i[3],
                 desc=i[4],
                 dateadded=CreateRandomDate(),
                 category=category)
    session.add(category)
    session.add(item1)
    session.add(item2)
    session.commit()

user_list = [('Michael Spurgin', '*****@*****.**')]

for elem in user_list:
    newUser = Users(name=elem[0], email=elem[1])
    session.add(newUser)
    session.commit()

print('Categories have been added')
print('Items have been added')
Ejemplo n.º 9
0
# 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()

# Users
User1 = Users(email="*****@*****.**")
session.add(User1)

# COUNTRIES
Australia = Countries(name="Australia")
Canada = Countries(name="Canada")
US = Countries(name="United States")
Greece = Countries(name="Greece")
France = Countries(name="France")
session.add(Australia)
session.add(Canada)
session.add(US)
session.add(Greece)
session.add(France)

# PLACES
Ejemplo n.º 10
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from db_setup import Base, Category, Items, Users

# Create database and create a shortcut for easier to update database
engine = create_engine('sqlite:///appitemcatalog.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

# Creating an user
user_one = Users(name="admin", email="*****@*****.**")
session.add(user_one)
session.commit()

# Transportation
category_one = Category(user_id=1, name="Transportation")
session.add(category_one)
session.commit()

# Household
category_two = Category(user_id=1, name="Household")
session.add(category_two)
session.commit()

# Adding items into Category
item = Items(user_id=1, name="Tires",
             description="Tires made of Rubber"
             "They are the main parts in vehicles.",
             Category=category_one)
session.add(item)
Ejemplo n.º 11
0
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine

from db_setup import Users, Category, Base, BookDetails

engine = create_engine('sqlite:///bookstore.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)

session = DBSession()
# the main user details are added
User1 = Users(name="srinivas veeragommula",
              email="*****@*****.**",
              picture='https://bit.ly/2JW7QK5')
session.add(User1)
session.commit()

# first category is added
categories1 = Category(user_id=1,
                       name="Poetry",
                       description="Poetry is an art"
                       "form in which human language is used"
                       "for its aesthetic qualities in addition to, or instead"
                       "of,its notional and semantic content.")

session.add(categories1)
session.commit()

# the first category bookdetails
book = BookDetails(user_id=1,