]> git.phdru.name Git - m_librarian.git/blobdiff - m_librarian/web/app.py
Style(app): Rename `id`
[m_librarian.git] / m_librarian / web / app.py
index d34b9df64f83fc6b8521af7364e5b5b19927a67b..31289b8d4f510652ecf046388565fe0cfdcde996 100644 (file)
@@ -69,32 +69,29 @@ def search_authors_post():
     }
 
 
-@route('/books-by-author/<id:int>/', method='GET')
-@cheetah_view('books_by_author.tmpl')
-def books_by_author(id):
+@route('/books-by-author/<aid:int>/', 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,
-            'columns': columns,
-        }
     else:
-        return {
-            'author': Author.get(id),
-            'books': Book.select(
-                Book.j.authors & (Author.q.id == id),
-                orderBy=['series', 'ser_no', 'title'],
-            ),
-            'columns': columns,
-        }
+        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/<filename:path>')
@@ -110,11 +107,16 @@ def send_static(filename):
 @route('/download/', method='POST')
 @cheetah_view('download.tmpl')
 def download_books():
-    books_ids = request.forms.getall('books')
+    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'Книги сохранены.',