示例#1
0
def newBookItem(book_id):
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newItem = BookItem(name=request.form['name'], book_id=book_id)
        session.add(newItem)
        session.commit()
        flash("A new book has been added")
        return redirect(url_for('bookItem', book_id=book_id))
    else:
        return render_template('newbookitem.html', book_id=book_id)
示例#2
0
def addBook():
    try:
        user_id = login_session["user_id"]
        if(request.method == 'POST'):
            title = request.form['title']
            author = request.form['author']
            desc = request.form['description']
            genre = request.form['genre']
            thisGenre = session.query(Genre).filter(
                Genre.name == genre, Genre.user_id == user_id).one()
            # checks to see if book title and genre are duplicates, will
            # not add them if they both are
            if(not session.query(exists().where(
                    BookItem.title == title).where(
                    BookItem.user_id == thisGenre.user_id)).scalar()):
                    newBook = BookItem(
                        title=title, author=[author], description=desc,
                        genre=thisGenre, imgURL=None,
                        user_id=thisGenre.user_id)
                    session.add(newBook)
                    session.commit()
                    thisBook = session.query(BookItem).filter(
                            BookItem.title == title,
                            BookItem.user_id == user_id).one()
                    flash(thisBook.title + " added!")
            else:
                try:
                    thisBook = session.query(BookItem).filter(
                        BookItem.title == title,
                        BookItem.genre_id == thisGenre.id).one()
                    flash(thisBook.title + " already exists in your collection!")
                except exc.NoResultFound:
                    thisBook = session.query(BookItem).filter(
                        BookItem.title == title,
                        BookItem.user_id == user_id).one()
                    bookGenre = session.query(Genre).filter(Genre.id == thisBook.genre_id).one()
                    genre = bookGenre.name
                    flash(thisBook.title + " already exists in the " + genre + " genre!")

            return redirect(url_for(
                'viewPage',
                super_category_name=thisGenre.super_category.name,
                genre_name=genre, book_title=thisBook.title, _external=True).replace("http://", "https://www."))
        else:
            allMyGenres = session.query(Genre).filter_by(user_id=user_id).all()
            return render_template('new-book.html', allGenres=allMyGenres)
    except KeyError:
        return redirect(url_for('loginPage', _external=True).replace("http://", "https://www."))
示例#3
0
def newBookItem(genre_id):
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newItem = BookItem(name=request.form['name'],
                           description=request.form['description'],
                           author=request.form['author'],
                           price=request.form['price'],
                           genre_id=genre_id,
                           user_id=login_session['user_id'])
        session.add(newItem)
        session.commit()
        flash("New book created!")
        return redirect(url_for('genrelist', genre_id=genre_id))
    else:
        return render_template('newbookitem.html', genre_id=genre_id)
示例#4
0
def newBookItem(genre_id):
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newBookItem = BookItem(name=request.form['name'],
                               description=request.form['description'],
                               price=request.form['price'],
                               author=request.form['author'],
                               year_published=request.form['year'],
                               genre_id=genre_id,
                               user_id=login_session['user_id'])
        session.add(newBookItem)
        session.commit()
        flash("New Book has been added!")
        return redirect(
            url_for('genreBooks', genre_id=genre_id, user=login_session))
    else:
        return render_template('book_new.html',
                               genre_id=genre_id,
                               user=login_session)
示例#5
0
def newBookItem(genre_id):
    genre = session.query(Genre).filter_by(id=genre_id).one()
    if login_session['user_id'] != genre.user_id:
        return "<script>function myFunction() {alert('You are not authorized to add \
                 menu items to this genre. \
                 Please create your own genre in order to \
                 add items.');}</script><body onload='myFunction()'>"

    if request.method == 'POST':
        newBookItem = BookItem(title=request.form['title'],
                               description=request.form['description'],
                               author=request.form['author'],
                               price=request.form['price'],
                               coverUrl=request.form['coverUrl'],
                               edition=request.form['edition'],
                               genre_id=genre_id,
                               user_id=genre.user_id)
        session.add(newBookItem)
        session.commit()
        flash('New Book %s Item Successfully Created' % (newBookItem.title))
        return redirect(url_for('showMenu', genre_id=genre_id))
    else:
        return render_template('newbookitem.html', genre_id=genre_id)
示例#6
0
# 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()

# Books for Sci Fi
genre1 = Genre(name="Sci Fi")

session.add(genre1)
session.commit()

bookItem2 = BookItem(user_id=1,
                     name="My Sister Keeper",
                     description="The \
                     difficult choices a family must make when a child is \
                     diagnosed with a serious disease",
                     price="$7.50",
                     author="Jody Picoult",
                     genre=genre1)

session.add(bookItem2)
session.commit()

bookItem1 = BookItem(user_id=1,
                     name="The E-Myth Revisited",
                     description="How \
                     to win at business with systems",
                     price="$12.99",
                     author="Michael E. Gerber",
                     genre=genre1)
示例#7
0
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Adding a list of books in the book1 category
book1 = Book(name="Motivational Books")

session.add(book1)
session.commit()

bookItem1 = BookItem(
    name="The Alchemist",
    description="Paulo Coelho's"
    "masterpiece tells the magical story of Santiago, an"
    "Andalusian shepherd boy who yearns to travel in search"
    "of a worldly treasure as extravagant as any ever found."
    "The story of the treasures Santiago finds along the way "
    "teaches us, as only a few stories can, about the essential"
    "wisdom of listening to our hearts, learning to read the omens"
    "strewn along life's path, and, above all, following our dreams.",
    price="$14.50",
    books=book1)

session.add(bookItem1)
session.commit()

bookItem2 = BookItem(
    name="Winning",
    description="The core of Winning is devoted to the real stuff of work."
    "This main part of the book is split into three sections. The first looks"
    "inside the company, from leadership to picking winners to making change"
    "happen. The second section looks outside, at the competition, with chapters"
示例#8
0
    'https://plus.google.com/u/0/photos/103754540034105626879/albums/profile/5731836629516512290'
)
session.add(User1)
session.commit()

# Menu for Crime
genre1 = Genre(user_id=1, title="Crime")

session.add(genre1)
session.commit()

bookItem1 = BookItem(
    user_id=1,
    title="A Dark So Deadly",
    description="No.1 bestselling author of the Logan McRae series.",
    price="$11.99",
    coverUrl="""http://goo.gl/v3ejVQ""",
    author="Stuart MacBride",
    edition="hardcover",
    genre=genre1)

session.add(bookItem1)
session.commit()

bookItem2 = BookItem(
    user_id=1,
    title="Sweet Little Lies",
    description=
    "In 1998, Maryanne Doyle disappeared and Dad knew something about it?.",
    price="$3.71",
    coverUrl="""http://goo.gl/VHdk5x""",
示例#9
0
Genre_II = Genre(name="Science Fiction",
                 super_category=SuperCategory_I,
                 user_id=1)
session.add(Genre_II)

Genre_III = Genre(name="Self-Help", super_category=SuperCategory_II, user_id=1)
session.add(Genre_III)

Genre_IV = Genre(name="Law", super_category=SuperCategory_II, user_id=1)
session.add(Genre_IV)

# Add one book per genre to start!
Book_I = BookItem(title="The Hobbit",
                  author=["J.R.R. Tolkien"],
                  description="A classic fantasy adventure masterpiece, which \
        introduces Middle-Earth to most readers, and serves as a prequel to \
        Tolkien's Lord of the Rings epic saga.",
                  genre=Genre_I,
                  imgURL=None,
                  user_id=1)
session.add(Book_I)

Book_II = BookItem(
    title="Hyperion",
    author=["Dan Simmons"],
    description="A Hugo Award-winning science fiction novel, which \
        details the journey of a special force of 'pilgrims' to the planet \
        Hyperion, who were all connected to the planet in the past and are \
        now tasked with unravelling its secrets. Story is comprised of \
        multiple narrative accounts of the 'pilgrims' past connection to \
        Hyperion, and is structured in the same way as the Canterbury Tales - \
        stories told on-route to their destination!",
示例#10
0
genre6 = Genre(name="Science Fiction", user_id=1)
session.add(genre1)
session.add(genre2)
session.add(genre3)
session.add(genre4)
session.add(genre5)
session.add(genre6)
session.commit()

# Import BookItems
bookItem1 = BookItem(name="Atlas of Human Anatomy",
                     description='''The gold standard of excellence for 25
                     years, Frank H. Netter, MD's Atlas of Human Anatomy offers
                     unsurpassed depictions of the human body in clear,
                     brilliant detail - all from a clinician's
                     perspective...''',
                     price="$75.00",
                     author="Frank H. Netter",
                     year_published=1989,
                     genre=genre1,
                     user_id=1)
bookItem2 = BookItem(name="Guns, Germs, and Steel",
                     description='''Guns, Germs, and Steel: The Fates of Human
                     Societies is a 1997 transdisciplinary non-fiction book by
                     Jared Diamond, professor of geography and physiology at
                     the University of California, Los Angeles.''',
                     price="$10.00",
                     author="Jared Diamond",
                     year_published=1997,
                     genre=genre2,
                     user_id=1)