def newCategory():
    if request.method == 'POST':
        newCat = Category(title=request.form['name'])
        session.add(newCat)
        session.commit()
        flash("new category created")
        return redirect(url_for('showCatalog'))
    else:
        return render_template('newcategory.html')
Пример #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')
Пример #3
0
def newCategory():
    DBSession = sessionmaker(bind=engine)
    session = DBSession()
    if request.method == 'POST':
        # added authentication check per review feedback
        # can't create new category if not logged in
        if 'username' not in login_session:
            return redirect(url_for('showLogin'))
        # create new category in DB and redirect to showItems on submit
        newCategory = Category(name=request.form['name'])
        session.add(newCategory)
        session.commit()
        return redirect(url_for('showItems'))
    else:
        return render_template('newCategory.html')
def createCategory(name, description, user_id):
    """
    Create a new category in the database.

    Args:
            name: The name for the new category
            description: A description of the new category
            user_id: The id of the user creating the category

    Returns:
            Nothing
    """

    newCategory = Category(name=name, description=description, user_id=user_id)
    session.add(newCategory)
    session.commit()
Пример #5
0
def new_category():
    # Allows a logged in user to add a new category, with him as its owner
    if request.method == "GET":
        return render_template("add_category.html")

    # Processing Post Request
    name = request.form.get("name")

    validation_result = validate_creation("Category", name)
    valid = validation_result[0]
    message = validation_result[1]
    flash(message)

    if valid:
        category = Category(name=name, user_id=login_session["user_id"])
        session.add(category)
        session.commit()
        return redirect("/")
    else:
        return render_template("add_category.html")
# 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()

#super user
sudo = User(id=1, email="*****@*****.**", username="******")
session.query(User).filter(User.id == sudo.id).delete()
session.commit()
session.add(sudo)
session.commit()

# Game Categories pulled from Wikipedia
# https://en.wikipedia.org/wiki/List_of_video_game_genres
category1 = Category(title="Platform")

session.add(category1)
session.commit()

categoryGame1 = Item(
    title="Donkey Kong",
    description="""Donkey Kong is considered to be the earliest
                    video game with a storyline that visually unfolds on
                    screen. The eponymous Donkey Kong character is the
                    game's de facto villain. The hero is a carpenter
                    originally unnamed in the Japanese arcade release,
                    later named Jumpman and then Mario. The ape kidnaps
                    Mario's girlfriend, originally known as Lady, but later
                    renamed Pauline. The player must take the role of Mario
                    and rescue her. This is the first occurrence of the
Пример #7
0
# old engine:
# engine = create_engine('sqlite:///catalog3.db')
engine = create_engine('postgresql://*****:*****@localhost/catalog')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

# delete from tables to initialize
num_rows_deleted = session.query(Category).delete()
session.commit()

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

golfCat = Category(name="Golf")
session.add(golfCat)
session.commit()

baseballCat = Category(name="Baseball")
session.add(baseballCat)
session.commit()

tennisCat = Category(name="Tennis")
session.add(tennisCat)
session.commit()

skiCat = Category(name="Downhill Skiing")
session.add(skiCat)
session.commit()
Пример #8
0
try:
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()
except:



#Items for Electric Guitars
category1 = Category(name = "Electric Guitars")

session.add(category1)
session.commit()


categoryItem1 = CategoryItem(name = "Fender Limited Edition Standard Stratocaster", description = "Value, tone, and limited edition style.", price = "$599.99", category = category1, user_id = 1, )

session.add(categoryItem1)
session.commit()

categoryItem2 = CategoryItem(name = "PRS John Mayer Silver Sky Electric Guitar", description = "Extraordinary attention to detail makes for a stellar signature guitar.", price = "$2299.50", category = category1)

session.add(categoryItem2)
session.commit()
Пример #9
0
# 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()

category1 = Category(name='Soccer', description='The other football')

session.add(category1)
session.commit()

category2 = Category(name='Basketball', description='Shooty Hoops')

session.add(category2)
session.commit()

category3 = Category(name='Baseball', description='Stickball')

session.add(category3)
session.commit()

category4 = Category(name='Frisbee', description='A sport?')