def addItem(): if 'username' not in login_session: return redirect('/login') if (request.method == 'POST'): category = Category(name=request.form['category_name'], user_id=login_session.get('user_id')) session.add(category) session.commit() newItem = Item(name=request.form['name'], category=category, user_id=login_session.get('user_id')) session.add(newItem) session.commit() description = Description(description=request.form['description'], item=newItem) session.add(description) session.commit() return redirect(url_for('categories')) else: return render_template('newitem.html')
def newCategoryItem(category_id): category = session.query(Category).filter_by(id=category_id).one_or_none() if category is None: flash('Oops, that category does not exist in the catalog!') return redirect(url_for('showCatalog')) if 'username' not in login_session: flash('You are not allowed to add items until you login!') return redirect('/login') if request.method == 'POST': newItem = Item(name=request.form['name'], description=request.form['description'], price=request.form['price'], category_id=category.id, user_id=login_session['user_id']) session.add(newItem) flash('Item successfully added to %s.' % category.name) session.commit() return redirect(url_for('showItems', category_id=category_id)) else: return render_template('newitem.html') flash('Something went wrong, please try again!')
def newItem(): catagory = session.query(Category).order_by(asc(Category.name)) items = session.query(Item).order_by(desc(Item.id)).limit(5) user = session.query(User).filter_by(email=login_session['email']).one() if 'username' not in login_session: return render_template('publiccatalog.html', catagory=catagory, items=items) else: if request.method == 'POST': newItem = Item(name=request.form['name'], description=request.form['des'], category_name=request.form['cat'], user_id=user.id) # newItem = Item(name = request.form['name'] , description = request.form['des'] , category_name = request.form['cat']) session.add(newItem) session.commit() flash('New Menu %s Item Successfully Created' % (newItem.name)) return redirect( url_for('showMenu', catagory_name=request.form['cat'])) else: return render_template('additem.html', catagory=catagory)
def newCategoryItem(category_id): category = session.query(Category).filter_by(id=category_id).one() if 'username' not in login_session: flash('You are not allowed to add items until you login!') return redirect('/login') if request.method == 'POST': if request.files['file']: image = request.files['file'] filename = secure_filename(image.filename) image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) newItem = Item(name=request.form['name'], description=request.form['description'], price=request.form['price'], picture=filename, category_id=category.id, user_id=login_session['user_id']) session.add(newItem) flash('Item successfully added to %s.' % category.name) session.commit() return redirect(url_for('showItems', category_id=category_id)) else: return render_template('newitem.html') flash('Something went wrong, please try again!')
DBSession = sessionmaker(bind=engine) session = DBSession() # First User user1 = User(id=1, name="Sean Magrann", email="*****@*****.**") session.add(user1) session.commit() # Categories and Items category1 = Category(name="Dry Flies", image="dryflies.jpg", user=user1) session.add(category1) session.commit() item1 = Item(name="Elk Hair Caddis", description="Most effective Caddis pattern out there!", price="$3.99", picture="elkhair.jpg", category=category1, user=user1) session.add(item1) session.commit() item2 = Item(name="Parachute Adams", description="The most commonly used dry fly ever!", price="$3.99", picture="parachute.jpg", category=category1, user=user1) session.add(item2) session.commit() item3 = Item(name="Light Cahill",
# session.rollback() session = DBSession() # Create dummy user User1 = User(name="Robo Barista", email="*****@*****.**", picture='https://pbs.twimg.com/profile_images.png') session.add(User1) session.commit() # Menu for Soccer category1 = Category(user_id=1, name="Soccer") session.add(category1) session.commit() Item2 = Item( user_id=1, name="Shinguards", description= "A shin guard is a piece of equipment worn on the front of a players shin ", category=category1) session.add(Item2) session.commit() Item1 = Item(user_id=1, name="Shorts", description="Goalkeepers are allowed to wear tracksuit bottoms .", category=category1) session.add(Item1) session.commit() Item3 = Item( user_id=1,