X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fweb%2Fapp.py;h=31289b8d4f510652ecf046388565fe0cfdcde996;hb=054ce4ecc6c93d0289864c80677c7dd8bf8b1962;hp=9991bb714f6fc9ea0653152f60a71929c4b2c0cd;hpb=8fdf6aab492482fcacad9ce2ec764bdc5bf76590;p=m_librarian.git diff --git a/m_librarian/web/app.py b/m_librarian/web/app.py index 9991bb7..31289b8 100644 --- a/m_librarian/web/app.py +++ b/m_librarian/web/app.py @@ -59,37 +59,39 @@ def search_authors_post(): )] authors = search_authors(search_type, case_sensitive, {}, expressions, orderBy=('surname', 'name', 'misc_name')) + columns = get_config().getlist('columns', 'author', ['fullname']) return { 'authors': list(authors), 'search_authors': value, 'search_type': search_type, 'case_sensitive': case_sensitive, + 'columns': columns, } -@route('/books-by-author//', method='GET') -@cheetah_view('books_by_author.tmpl') -def books_by_author(id): +@route('/books-by-author//', method='GET') +@cheetah_view('list_books.tmpl') +def books_by_author(aid): use_filters = get_config().getint('filters', 'use_in_books_list', 1) + columns = get_config().getlist('columns', 'book', ['title']) + author = Author.get(aid) if use_filters: join_expressions = [] join_expressions.append(Book.j.authors) - join_expressions.append(Author.q.id == id) + join_expressions.append(Author.q.id == aid) books = search_books('full', None, {}, join_expressions, - orderBy=('series', 'ser_no', 'title'), + orderBy=('series', 'ser_no', 'title', '-date'), 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'], - ) - } + books = Book.select( + Book.j.authors & (Author.q.id == aid), + orderBy=['series', 'ser_no', 'title'], + ) + + return { + 'books_by_author': {author.fullname: list(books)}, + 'columns': columns, + } @route('/static/') @@ -105,11 +107,16 @@ def send_static(filename): @route('/download/', method='POST') @cheetah_view('download.tmpl') def download_books(): - books_ids = request.forms.getall('books') - download_path = get_config().get('download', 'path') or '.' + books_ids = [] + form = request.forms + for k in form: + if k.split('_')[-1] == 'books': + for bid in form.getall(k): + books_ids.append(bid) + download_path = get_config().getpath('download', 'path') if books_ids: - for id in books_ids: - book = Book.get(int(id)) + for bid in books_ids: + book = Book.get(int(bid)) download(book, download_path) return { 'message': u'Книги сохранены.', @@ -151,15 +158,17 @@ def search_books_post(): orderBy=('title',), use_filters=use_filters) books_by_authors = {} for book in books: - author = book.authors[0].fullname + author = book.author1 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) + columns = get_config().getlist('columns', 'book', ['title']) return { 'books_by_author': books_by_authors, 'search_books': value, 'search_type': search_type, 'case_sensitive': case_sensitive, + 'columns': columns, }