コード例 #1
0
ファイル: main.py プロジェクト: IvanDimitrov2002/subd-project
def update_book():
    books = None
    book = None

    if request.method == 'GET':
        book = Book.find_by_id(request.args.get('id'))
        authors = book.get_book_authors()
        if (authors):
            book.authors = ','.join([author[1] for author in authors])
        if book:
            return render_template('update_book.html', book=book)

    if request.method == 'POST':
        form = request.form
        book = Book.find_by_id(form['id'])
        print(form)
        if book:
            book.date = form['date']
            book.genre = form['genre']
            book.isbn = form['isbn']
            book.title = form['title']
            book.authors = [
                author.strip() for author in request.form['authors'].split(',')
            ]
            book.update_book()
        if book:
            return render_template('books.html', books=[book])

    books = Book.get_all_books()
    if books:
        return render_template('books.html', books=books)

    return render_template('index.html')
コード例 #2
0
ファイル: main.py プロジェクト: IvanDimitrov2002/subd-project
def view_books():
    books = None
    if request.method == 'GET':
        req = request.args

        if req.get('title') and req.get('title') != "":
            books = Book.find_by_substring(req.get('title'))

        elif req.get('genre') and req.get('genre') != "":
            books = Book.find_by_genre(req.get('genre'))

        elif req.get('author') and req.get('author') != "":
            books = Book.find_by_author(req.get('author'))

    if request.method == 'POST':
        if request.form["target"] == 'delete':
            Book.delete_book_by_id(request.form["id"])

    if not books:
        books = Book.get_all_books()

    if books:
        for book in books:
            authors = book.get_book_authors()
            if (authors):
                book.authors = [author[1] for author in authors]
        return render_template('books.html', books=books)

    return render_template('index.html')