def newCategory(): if 'username' not in login_session: return redirect('/login') user_id = login_session['user_id'] if request.method == 'POST': if request.form['name']: name = request.form['name'] if request.form['category']: parent = request.form['category'] parent = None # Create a new category new = Category(name=name, parentid=parent, user_id=user_id) session.add(new) session.commit() flash('You have successfully created a new category') return redirect(url_for('newCategory')) else: # Check if all required fields are filled out properly flash('Category name is required.') return redirect(url_for('newCategory')) else: category = session.query(Category).all() return render_template('newCategory.html', user_id=user_id, category=category)
def newCategory(): # Get categories categories = session.query(Category).order_by(asc(Category.name)) 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', categories=categories)
def newCategorie(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': print "creating a new catagory" creator = getUserInfo(login_session['user_id']) newCategorie = Category(name=request.form['name'], user_id=creator.id) if newCategorie is not None: session.add(newCategorie) flash('New Categorie %s Successfully Created' % newCategorie.name) session.commit() return redirect(url_for('showCatalog')) else: return render_template('newCategorie.html')
def create_category(name): new_category = Category(name=name) session.add(new_category) session.commit() return new_category.id
) session.add(user1) session.commit() # User 2 user2 = User( name="Veronica", email="*****@*****.**", picture= "https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png" ) session.add(user2) session.commit() # Items for Snowboard category1 = Category(name="Snowboarding", user=user1) session.add(category1) session.commit() catalogItem1 = CatalogItem( name="Snowboard", description= "Size and shape variances in the boards accommodate for different snow conditions and riding styles. Shorter boards are typically considered youth size and designed for use by children, though some varieties of short boards are specifically designed for a special purpose, such as the performance of snowboarding tricks. Such tricks may take place in a snowpark alongside freestyle skiers.", category=category1, user=user1) session.add(catalogItem1) session.commit() catalogItem2 = CatalogItem(
# 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() # New category Soccer category1 = Category(name="Soccer") session.add(category1) session.commit() # Items under Soccer categoryItem1 = CategoryItem( name="Shinguards", description="Shinguards are use to protect the shins", category=category1) session.add(categoryItem1) session.commit() categoryItem2 = CategoryItem(name="Two shinguards", description="Pair of Shinguards",