def search(page): search_type = request.args.get('type', 'books') search_term = request.args.get('term', '') curr_author_id = request.args.get('curr_author_id') if search_type not in ('authors', 'books'): search_type = 'books' if search_type == 'authors': authors = authors_sorted(Author.search_by_last_name(search_term)) authors_pager = authors.paginate(page, ITEMS_PER_PAGE) return render_template( 'authors_search_results.html', authors_pager=authors_pager, search_term=search_term, search_type=search_type ) elif search_type == 'books': books = books_sorted(Book.search_by_title(search_term)) books_pager = books.paginate(page, ITEMS_PER_PAGE) return render_template( 'books_search_result.html', books_pager=books_pager, search_term=search_term, search_type=search_type, curr_author_id=curr_author_id ) assert False, "Uknown search type"
def authors_chooser(page): prefix = request.args.get('prefix', '') authors_pager = None if prefix: authors = authors_sorted(Author.search_starting_from(prefix)) authors_pager = authors.paginate(page, ITEMS_PER_PAGE) return render_template( 'authors_chooser.html', prefix=prefix, authors_pager=authors_pager )