コード例 #1
0
ファイル: project.py プロジェクト: jaustinlam/aloha-library
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)
コード例 #2
0
ファイル: project.py プロジェクト: jaustinlam/aloha-library
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)
コード例 #3
0
ファイル: project.py プロジェクト: jaustinlam/aloha-library
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)
コード例 #4
0
ファイル: project.py プロジェクト: jaustinlam/aloha-library
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)
コード例 #5
0
ファイル: project.py プロジェクト: jaustinlam/aloha-library
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)