def newLibrary(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newLibrary = Library(name=request.form['name'], user_id=login_session['user_id']) session.add(newLibrary) flash('New Library %s Successfully Created' % newLibrary.name) session.commit() return redirect(url_for('showLibrarys')) else: return render_template('newLibrary.html')
def newLibrary(): """ Method: Create a new library. Return: New library form. """ if request.method == 'POST': newLibrary = Library(name=request.form['name'], user_id=login_session['user_id']) session.add(newLibrary) flash('New library %s added to the Library list' % newLibrary.name) session.commit() return redirect(url_for('showLibraries')) else: return render_template('newLibrary.html', user=login_session['username'])
def addLibrary(): """Add a new library Returns: on GET: Page to add a new library on POST: Redirct to main page after adding a new library """ if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newLibrary = Library(name=request.form['name'], user_id=login_session['user_id']) session.add(newLibrary) flash('New Library %s Successfully Created' % newLibrary.name) session.commit() return redirect(url_for('showLibrary')) else: return render_template('addLibrary.html')
# 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() # Create dummy user User1 = User(name="Robo Barista", email="*****@*****.**") session.add(User1) session.commit() # Menu for UrbanBurger library1 = Library(user_id=1, name="Kids Books") session.add(library1) session.commit() menuItem2 = MenuItem(user_id=1, name="Amelia Bedelia", description="The queen of idioms", price="$17.50", course="Short Story", library=library1) session.add(menuItem2) session.commit() menuItem1 = MenuItem(user_id=1,
# 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() # Create dummy user User1 = User(name="Steven Yang", email="*****@*****.**", picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png') session.add(User1) session.commit() # Thompson Library library1 = Library(user_id=1, name="Thompson Library") session.add(library1) session.commit() book1 = Book(user_id=1, name="INTRODUCING POLITICAL PHILOSOPHY", description="Essential illustrated guide to key ideas of political thought. ", published_year=2011, author="DAVE ROBINSON", library=library1) session.add(book1) session.commit() book2 = Book(user_id=1, name="INTRODUCING MARX", description="Compact INTRODUCING guide to the influential philosopher, sociologist and economist.", published_year=2012, author="RIUS", library=library1) session.add(book2)
# Create dummy user User1 = User(name="Sadman Chowdhury", email="*****@*****.**", picture='https://bit.ly/2RyWFaU') session.add(User1) session.commit() User2 = User(name="Jordan Mike", email="*****@*****.**", picture='https://bit.ly/2roAx7y') session.add(User2) session.commit() # Menu for UrbanBurger Library1 = Library(user_id=1, name="Heirloom Library") session.add(Library1) session.commit() Library2 = Library(user_id=2, name="Idle Hour Library") session.add(Library2) session.commit() Library3 = Library(user_id=1, name="Epiphany Library") session.add(Library3) session.commit() Library4 = Library(user_id=2, name="Illusions Library")