X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fweb%2Fapp.py;h=42c5c5a632bee899df2105b1be5c214cd453557c;hb=63bb5df8cf2595bbe106031911666fb7061a03aa;hp=19fca6c4254076abb46c3b6c23c66f54656de2c7;hpb=fdede95cc489c5519b2e38130d66d4c01775e341;p=m_librarian.git diff --git a/m_librarian/web/app.py b/m_librarian/web/app.py index 19fca6c..42c5c5a 100644 --- a/m_librarian/web/app.py +++ b/m_librarian/web/app.py @@ -14,7 +14,9 @@ from m_librarian.search import search_authors, search_books @route('/') @cheetah_view('index.tmpl') def index(): - return {} + return { + 'get_config': get_config, + } @route('/search_authors', method='GET') @@ -68,13 +70,26 @@ def search_authors_post(): @route('/books-by-author//', method='GET') @cheetah_view('books_by_author.tmpl') def books_by_author(id): - return { - 'author': Author.get(id), - 'books': Book.select( - Book.j.authors & (Author.q.id == id), - orderBy=['series', 'ser_no', 'title'], - ) - } + use_filters = get_config().getint('filters', 'use_in_books_list', 1) + if use_filters: + join_expressions = [] + join_expressions.append(Book.j.authors) + join_expressions.append(Author.q.id == id) + books = search_books('full', None, {}, join_expressions, + orderBy=('series', 'ser_no', 'title'), + use_filters=use_filters) + return { + 'author': Author.get(id), + 'books': books, + } + else: + return { + 'author': Author.get(id), + 'books': Book.select( + Book.j.authors & (Author.q.id == id), + orderBy=['series', 'ser_no', 'title'], + ) + } @route('/static/') @@ -91,7 +106,7 @@ def send_static(filename): @cheetah_view('download.tmpl') def download_books(): books_ids = request.forms.getall('books') - download_path = get_config().get('download', 'path') + download_path = get_config().getpath('download', 'path') if books_ids: for id in books_ids: book = Book.get(int(id)) @@ -113,7 +128,9 @@ def _search_books(): @route('/search_books/', method='GET') @cheetah_view('search_books.tmpl') def search_books_get(): - return {} + return { + 'get_config': get_config, + } @route('/search_books/', method='POST') @@ -129,10 +146,19 @@ def search_books_post(): case_sensitive = request.forms.get('case_sensitive') if case_sensitive is None: case_sensitive = _guess_case_sensitivity(value) + use_filters = request.forms.get('use_filters') books = search_books(search_type, case_sensitive, {'title': value}, None, - orderBy=('title',)) + orderBy=('title',), use_filters=use_filters) + books_by_authors = {} + for book in books: + author = book.authors[0].fullname + if author in books_by_authors: + books_by_author = books_by_authors[author] + else: + books_by_author = books_by_authors[author] = [] + books_by_author.append(book) return { - 'books': list(books), + 'books_by_author': books_by_authors, 'search_books': value, 'search_type': search_type, 'case_sensitive': case_sensitive,