def newBook(): if request.method == 'POST': # check if the user is logged-in or not if 'provider' in login_session and \ login_session['provider'] != 'null': # the book name bookName = request.form['bookName'] # the book author bookAuthor = request.form['authorName'] # url of the cover coverUrl = request.form['bookImage'] # descripcion del libro description = request.form['bookDescription'] # description description = description.replace('\n', '<br>') # cateogria del libro bookCategory = request.form['category'] user_id = check_user().id # book condition if bookName and bookAuthor and coverUrl and description \ and bookCategory: # new book newBook = BookDB( # book characteristics bookName=bookName, authorName=bookAuthor, # url of the cover coverUrl=coverUrl, description=description, # categoria of the book category=bookCategory, user_id=user_id, ) session.add(newBook) session.commit() return redirect(url_for('showBooks')) else: state = new_state() return render_template( 'newItem.html', currentPage='new', title='Add New Book', errorMsg='ohh, All the Fields are Required!', state=state, login_session=login_session, ) else: # set new state state = new_state() books = queryAllBooks() # render book return render_template( 'main.html', books=books, # set current page currentPage='main', state=state, login_session=login_session, errorMsg='Yoy need to Login first in order to Add a Book!', ) elif 'provider' in login_session and login_session['provider'] \ != 'null': # set new state of the book state = new_state() # render the template return render_template( 'newItem.html', currentPage='new', #characteristics of the book title='Add New Book', state=state, login_session=login_session) else: # set new state state = new_state() # query all books books = queryAllBooks() return render_template( 'main.html', # book characteristics books=books, # page currently reading currentPage='main', state=state, # login session of the user login_session=login_session, errorMsg='You need to Login first to Add Book!', )
category5 = CategoryDB(id=5, name="Horror") session.add(category5) session.commit() category6 = CategoryDB(id=6, name="Other") session.add(category6) session.commit() # Create dummy books data book1 = BookDB(id="1", bookName="Hello!", authorName="Janine Amos", coverUrl="bla bla", description="...", category="Other", user_id=1) session.add(book1) session.commit() book2 = BookDB(id="2", bookName="Romantic Poetry, Volume 7", authorName="Angela Esterhammer", coverUrl="bla bla", description="...", category="Romance", user_id=1)
def newBook(): if request.method == 'POST': # check if user is logged in or not if 'provider' in login_session and \ login_session['provider'] != 'null': Book_Title = request.form['Book_Title'] bookAuthor = request.form['Author'] URL = request.form['bookImage'] description = request.form['bookdescription'] description = description.replace('\n', '<br>') bookCategory = request.form['category'] user_id = check_user().id if Book_Title and bookAuthor and URL and description \ and bookCategory: newBook = BookDB( Book_Title=Book_Title, Author=bookAuthor, URL=URL, description=description, category=bookCategory, user_id=user_id, ) session.add(newBook) session.commit() return redirect(url_for('showBooks')) else: state = new_state() return render_template( 'newItem.html', currentPage='new', title='Add New Book', errorMsg='All Fields are Required!', state=state, login_session=login_session, ) else: state = new_state() books = queryAllBooks() return render_template( 'main.html', books=books, currentPage='main', state=state, login_session=login_session, errorMsg='Please Login first to Add Book!', ) elif 'provider' in login_session and login_session['provider'] \ != 'null': state = new_state() return render_template('newItem.html', currentPage='new', title='Add New Book', state=state, login_session=login_session) else: state = new_state() books = queryAllBooks() return render_template( 'main.html', books=books, currentPage='main', state=state, login_session=login_session, errorMsg='Please Login first to Add Book!', )
# 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="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books data book1 = BookDB(bookName="The Year of Taking Chances", authorName="Lucy Diamond", coverUrl="""https://books.google.com/books/content/ images/frontcover/F9uIBAAAQBAJ?fife=w300-rw""", description="hello", category="Romance", user_id=1) session.add(book1) session.commit() book2 = BookDB(bookName="Summoner: The Inquisition: Book 2", authorName="Taran Matharu", coverUrl="""https://books.google.com/books/content/images/ frontcover/sQAfCgAAQBAJ?fife=w300-rw""", description="hello", category="Fantasy", user_id=1) session.add(book2) session.commit()
engine = create_engine('sqlite:///BookCatalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Create user details User1 = User(name="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books catalog book1 = BookDB(Book_Title="Man's Search for Meaning", Author="Viktor E. Frankl ", URL="""http://www.fablar.in/yahoo_site_admin/ assets/docs/Mans_Search_for_Meaning.78114942.pdf""", description="talks about men's hope", category="Story", user_id=1) session.add(book1) session.commit() book2 = BookDB( Book_Title="The 48 Laws of Power", Author="Robert Greene", URL="""https://www.tke.org/files/file/The_48_Laws_of_Power.pdf""", description="Great laws to be a leader", category="Self-help", user_id=1)
def newBook(): categories = session.query(CategoryDB).all() if request.method == 'POST': # check if user is logged in or not if 'provider' in login_session and \ login_session['provider'] != 'null': bookName = request.form['bookName'] bookAuthor = request.form['authorName'] coverUrl = request.form['bookImage'] description = request.form['bookDescription'] description = description.replace('\n', '<br>') bookCategory = request.form['category'] user_id = check_user().id if bookName and bookAuthor and coverUrl and description \ and bookCategory: newBook = BookDB( bookName=bookName, authorName=bookAuthor, coverUrl=coverUrl, description=description, category=bookCategory, user_id=user_id, ) session.add(newBook) session.commit() return redirect(url_for('showBooks')) else: state = new_state() return render_template( 'newItem.html', currentPage='new', categories=categories, title='Add New Book', errorMsg='All Fields are Required!', state=state, login_session=login_session, ) else: state = new_state() books = queryAllBooks() return render_template( 'main.html', books=books, currentPage='main', state=state, login_session=login_session, errorMsg='Please Login first to Add Book!', ) elif 'provider' in login_session and login_session['provider'] \ != 'null': state = new_state() return render_template('newItem.html', categories=categories, currentPage='new', title='Add New Book', state=state, login_session=login_session) else: state = new_state() books = queryAllBooks() return render_template( 'main.html', books=books, currentPage='main', state=state, login_session=login_session, errorMsg='Login first!', )
# 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="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books data book1 = BookDB(bookName="Digital Fortress", authorName="DanBrown", coverUrl="static/images/df.jpg", description="a techno thriller", category="Thriller", user_id=1) session.add(book1) session.commit() book2 = BookDB(bookName="SorceresRing", authorName="Morgan Rice", coverUrl="static/images/sr.jpg", description="a royal fantasy series", category="Fantasy", user_id=1) session.add(book2) session.commit()
# 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() # creating a dummy user User1 = User(name="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books data book1 = BookDB(bookName="The way of the zen", authorName="Alan Watts", coverUrl="""https://books.google.com/books/content/ images/frontcover/F9uIBAAAQBAJ?fife=w300-rw""", description="bye", category="Romance", user_id=1) session.add(book1) session.commit() book2 = BookDB(bookName="Harry Potter", authorName="J.K Rowlings", coverUrl="""https://books.google.com/books/content/images/ frontcover/sQAfCgAAQBAJ?fife=w300-rw""", description="one", category="Fantasy", user_id=1)
# 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="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books data book1 = BookDB(bookName="Digital Fortress", authorName="DanBrown", coverUrl="""https://in.pinterest.com/ pin/481392647662076199/""", description="a techno thriller", category="thriller", user_id=1) session.add(book1) session.commit() book2 = BookDB(bookName="SorceresRing", authorName="Morgan Rice", coverUrl="""https://in.pinterest.com/ pin/418553359095569952/""", description="a royal fantasy series", category="Fantasy", user_id=1)
session = DBSession() # Create dummy user User1 = User(name="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books data book1 = BookDB( bookName="The Hobbit", authorName="J. R. R. Tolkien", coverUrl="""https://images.gr-assets.com/books/1371834025l/17157681.jpg""", description="The classic fantasy novel of a time before the dominion of " "men, " "this book introduces the reader to Tolkien\'s world of " "hobbits, dwarves, goblins and " "wizards. The story takes the form of a quest as the hobbit " "Bilbo Baggins joins Gandalf " "the wizard.", category_id=1, user_id=1) session.add(book1) session.commit() book2 = BookDB( bookName="The Woman in the Window", authorName="A. J. Finn", coverUrl="""https://images.gr-assets.com/books/1528225499l/40389527.jpg""", description="Anna Fox spends her day drinking wine, watching old movies, "
# revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Create dummy user User1 = User(name="admin", email="*****@*****.**") session.add(User1) session.commit() # Dummy books data book1 = BookDB(bookName="Pride and Prejudice", authorName="Jane Austen", coverUrl="""https://books.google.com.mx/books/content ?id=aQM50Iu3CZcC&printsec=frontcover&img=1&zoom=1 &edge=curl&imgtk=AFLRE73uPSn3jF37T-j9jz6cqJagVhciXypttUK9nss- Fd151EmJvB37jy9LoPsAna5VA8cicQqHaZkpBQqSWhd8j5s08CXfOuX0F7 vqQ0TvLeU4mjezDWPPzzNcB2i8NGrzeGsZDCWC""", description="""This sparkling tale of one of literature's most famous courtships focuses on a spirited family of sisters and their marriage-minded mother's attempts to see them well settled.""", category="Romance", user_id=1) session.add(book1) session.commit() book2 = BookDB(bookName="Harry Potter and the Prisoner of Azkaban", authorName="JK Rowling", coverUrl="""https://books.google.com.mx/books/content ?id=BPtbPgAACAAJ&printsec=frontcover&img=1&zoom=1 &imgtk=AFLRE71BymKe_TBHEjbg5wv7_lipWLKv-YiRLTDnVTNHU79BZdGQ l4nT0HHcJxdJeKVlImKFw2-ryO7tjdU3HbHemm2CL_1hxBLoOWqZZgDPnr