<s> from flask import render_template , redirect , url_for <EOL> from collection import app <EOL> from collection . forms import BookForm <EOL> from collection . documents import Book <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def new_book ( ) : <EOL> form = BookForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> form . save ( ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def list_books ( page = <NUM_LIT:1> ) : <EOL> title = u'<STR_LIT>' <EOL> pagination = Book . query . paginate ( page = page , per_page = <NUM_LIT:5> ) <EOL> return render_template ( '<STR_LIT>' , pagination = pagination , title = title ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def list_books_filtering ( letter , page = <NUM_LIT:1> ) : <EOL> title = u'<STR_LIT>' % letter . upper ( ) <EOL> pagination = Book . query . starting_with ( letter ) . paginate ( page = page , per_page = <NUM_LIT:5> ) <EOL> return render_template ( '<STR_LIT>' , pagination = pagination , <EOL> title = title , letter = letter ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def delete_book ( id ) : <EOL> book = Book . query . get_or_404 ( id ) <EOL> book . remove ( ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def edit_book ( id ) : <EOL> book = Book . query . get ( id ) <EOL> form = BookForm ( document = book ) <EOL> return render_template ( '<STR_LIT>' , form = form , book = book ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def update_book ( id ) : <EOL> book = Book . query . get ( id ) <EOL> form = BookForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> form . instance = book <EOL> form . save ( ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> form = BookForm ( document = book ) <EOL> return render_template ( '<STR_LIT>' , form = form , book = book ) </s>
