Exemple #1
0
def checkInBook(categories_id, book_id):
    ''' Check in a book from the library

        Args:
            categories_id = The id of the category
            book_id = The id of the book
    '''
    book = books_methods.bookFromID(book_id)
    user = login_methods.getUserBySession(session)
    lastcheckout = books_methods.lastCheckout(book.id)
    if request.method == 'POST':
        if user.id == lastcheckout.user_id or user.administrator is True:
            books_methods.checkInBook(book, user.id)
            flash("Successfully checked in %s" % book.title)
            return redirect(url_for('showBooks',
                                    categories_id=categories_id))
        elif user:
            flash("Sorry chap you can't check this in")
            return render_template('checkinbooks.html',
                                   categories_id=categories_id, book=book)
        else:
            flash("Sorry only logged in users can checkin books")
            return redirect(url_for('showLogin'))
    else:
        return render_template('checkinbooks.html',
                               categories_id=categories_id, book=book)
Exemple #2
0
def editBook(categories_id, book_id):
    ''' Edit a Book

        Args:
            categories_id = The id of the category
            book_id = The id of the book
    '''
    book = books_methods.bookFromID(book_id)
    user = login_methods.getUserBySession(session)
    if request.method == "POST":
        if user.id == book.user_id or user.administrator is True:
            if request.form['title'] != book.title:
                book.title = bleach.clean(request.form['title'])
            if request.form['isbn'] != book.isbn:
                book.isbn = bleach.clean(request.form['isbn'])
            if request.form['image'] != book.image:
                book.image = bleach.clean(request.form['image'])
            if request.form['author'] != book.author:
                book.author = bleach.clean(request.form['author'])
            if request.form['description'] != book.description:
                book.description = bleach.clean(request.form['description'])
            books_methods.editBook(book)
            flash("Successfully edited %s" % book.title)
            return redirect(url_for('showBooks',
                                    categories_id=categories_id,
                                    book_id=book_id))
        elif user:
            flash("Sorry you are not authorized to edit this book")
            return render_template('editbooks.html', book=book)
        else:
            flash("Sorry only logged in users can edit")
            return redirect(url_for('showLogin'))
    else:
        return render_template('editbooks.html', book=book)
Exemple #3
0
def categoriesBookJSON(category_id, book_id):
    ''' JSON for a single book

        Args:
            category_id = the id of the category
            book_id = the id of the book
    '''

    book = books_methods.bookFromID(book_id)
    return jsonify(Book=book.serialize)
Exemple #4
0
def checkOutBook(categories_id, book_id):
    ''' Check out a book from the library

        Args:
            categories_id = The id of the category
            book_id = The id of the book
    '''
    book = books_methods.bookFromID(book_id)
    user = login_methods.getUserBySession(session)
    if request.method == 'POST':
        if user:
            books_methods.checkOutBook(book, user.id)
            flash("Successfully checked out %s" % book.title)
            return redirect(url_for('showBooks',
                                    categories_id=categories_id))
        else:
            flash("Sorry only logged in users can checkout books")
            return redirect(url_for('showLogin'))
    else:
        return render_template('checkoutbooks.html',
                               categories_id=categories_id, book=book)
Exemple #5
0
def delBook(categories_id, book_id):
    ''' Delete a Book

        Args:
            categories_id = The id of the category
            book_id = The id of the book
    '''
    book = books_methods.bookFromID(book_id)
    user = login_methods.getUserBySession(session)
    if request.method == 'POST':
        if user.id == book.user_id or user.administrator is True:
            books_methods.delBook(book)
            flash("Successfully deleted book")
            return redirect(url_for('showBooks',
                                    categories_id=categories_id))
        elif user:
            flash("Sorry you are not authorized to delete this book")
            return render_template('delbooks.html', book=book)
        else:
            flash("Sorry only logged in users can delete")
            return redirect(url_for('showLogin'))
    else:
        return render_template('delbooks.html', book=book)