1 from sqlobject.sqlbuilder import CONCAT
2 from bottle import cheetah_view, redirect, request, route
4 from m_librarian.db import Author, AuthorBook, Book
5 from m_librarian.search import search_authors
9 @cheetah_view('index.tmpl')
14 @route('/search_authors', method='GET')
15 def _search_authors():
16 return redirect('/search_authors/')
19 @route('/search_authors/', method='GET')
20 @cheetah_view('search_authors.tmpl')
21 def search_authors_get():
26 if isinstance(value, bytes):
27 return value.decode('utf-8')
31 def _guess_case_sensitivity(value):
32 return not value.islower()
35 @route('/search_authors/', method='POST')
36 @cheetah_view('list_authors.tmpl')
37 def search_authors_post():
38 value = request.forms.get('search_authors')
40 return redirect('/search_authors/')
42 search_type = request.forms.get('search_type')
45 case_sensitive = request.forms.get('case_sensitive')
46 if case_sensitive is None:
47 case_sensitive = _guess_case_sensitivity(value)
49 CONCAT(Author.q.surname, ' ', Author.q.name, ' ', Author.q.misc_name),
52 authors = search_authors(search_type, case_sensitive, {}, expressions,
53 orderBy=('surname', 'name', 'misc_name'))
55 'authors': list(authors),
56 'search_authors': value,
57 'search_type': search_type,
58 'case_sensitive': case_sensitive,
62 @route('/books-by-author/<id:int>/', method='GET')
63 @cheetah_view('books_by_author.tmpl')
64 def books_by_author(id):
66 'author': Author.get(id),
68 Book.j.authors & (Author.q.id == id),
69 orderBy=['series', 'ser_no', 'title'],