Example #1
0
def NewCatalogItem():
    categories = session.query(Category).order_by(asc(Category.name))
    if request.method == 'POST':
        newItem = CatalogItem(name=request.form['name'],
                              description=request.form['description'],
                              category_name=request.form['category'])
        session.add(newItem)
        session.commit()
        flash('New CatalogItem %s Item Successfully Created' % (newItem.name))
        # return redirect(url_for('MainPage', restaurant_id=restaurant_id))
        return "successfully added !!!!!!!!!!!"
    else:
        return render_template('newcatalogitem.html', categories=categories)
def newCatalogItem():
    """return "This page will be for making a new catalog item" """
    categories = session.query(Category).all()
    if request.method == 'POST':
        addNewItem = CatalogItem(name=request.form['name'],
                                 description=request.form['description'],
                                 category_id=request.form['category'],
                                 user_id=login_session['user_id'])
        session.add(addNewItem)
        session.commit()
        flash("New catalog item created!", 'success')
        return redirect(url_for('showCatalog'))
    else:
        return render_template('new_catalog_item.html', categories=categories)
Example #3
0
def NewCatalogItem():
    if 'username' not in login_session:
        return redirect('/login')
    categories = session.query(Category).order_by(asc(Category.name))
    if request.method == 'POST':
        newItem = CatalogItem(name=request.form['name'],
                              description=request.form['description'],
                              category_name=request.form['category'],
                              user_name=login_session['username'])
        category_name = request.form['category']
        categoryCheck = session.query(Category).filter_by(
            name=category_name).one()
        if categoryCheck.user_name != login_session['username']:
            return "<script>function myFunction() {alert('You are not authorized to Create this item. Please create your own catalog item in your own category.');}</script><body onload='myFunction()''>"
        session.add(newItem)
        session.commit()
        flash('New CatalogItem %s Item Successfully Created' % (newItem.name))
        # return redirect(url_for('MainPage', restaurant_id=restaurant_id))
        return redirect("/mainpage")
    else:
        return render_template('newcatalogitem.html', categories=categories)
session.add(user2)
session.commit()

user3 = User(name="User3", uname="user3", email="*****@*****.**")
user3.hash_password("user3")
session.add(user3)
session.commit()

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

session.add(category1)
session.commit()

catalogItem1 = CatalogItem(name="Soccer1",
                           description="soccer1",
                           category=category1,
                           user=user1)
session.add(catalogItem1)
session.commit()

catalogItem2 = CatalogItem(name="Soccer2",
                           description="soccer2",
                           category=category1,
                           user=user1)
session.add(catalogItem2)
session.commit()

catalogItem3 = CatalogItem(name="Soccer3",
                           description="soccer3",
                           category=category1,
                           user=user1)