1 # -*- coding: utf-8 -*-
4 from bottle import cheetah_view, redirect, request, route, static_file
6 from ..config import get_config
8 from ..download import download
9 from ..search import search_authors_raw, books_by_author, search_books_raw
13 @cheetah_view('index.tmpl')
16 'get_config': get_config,
20 @route('/search_authors', method='GET')
21 def _search_authors():
22 return redirect('/search_authors/')
25 @route('/search_authors/', method='GET')
26 @cheetah_view('search_authors.tmpl')
27 def search_authors_get():
31 @route('/search_authors/', method='POST')
32 @cheetah_view('list_authors.tmpl')
33 def search_authors_post():
34 value = request.forms.get('search_authors')
36 return redirect('/search_authors/')
37 search_type = request.forms.get('search_type')
38 case_sensitive = request.forms.get('case_sensitive')
39 return search_authors_raw(value, search_type, case_sensitive)
42 @route('/books-by-author/<aid:int>/', method='GET')
43 @cheetah_view('list_books.tmpl')
44 def _books_by_author(aid):
45 return books_by_author(aid)
48 @route('/static/<filename:path>')
49 def send_static(filename):
51 filename, root=os.path.join(
52 os.path.dirname(__file__),
58 @route('/download/', method='POST')
59 @cheetah_view('download.tmpl')
64 if k.split('_')[-1] == 'books':
65 for bid in form.getall(k):
68 download_path = get_config().getpath('download', 'path')
70 book = Book.get(int(bid))
71 download(book, download_path)
73 'message': u'Книги сохранены.',
77 'message': u'Не выбрано книг для сохранения.',
81 @route('/search_books', method='GET')
83 return redirect('/search_books/')
86 @route('/search_books/', method='GET')
87 @cheetah_view('search_books.tmpl')
88 def search_books_get():
90 'get_config': get_config,
94 @route('/search_books/', method='POST')
95 @cheetah_view('list_books.tmpl')
96 def search_books_post():
97 value = request.forms.get('search_books')
99 return redirect('/search_books/')
100 search_type = request.forms.get('search_type')
101 case_sensitive = request.forms.get('case_sensitive')
102 use_filters = request.forms.get('use_filters')
103 return search_books_raw(value, search_type, case_sensitive, use_filters)