3 from sqlobject.sqlbuilder import CONCAT
4 from bottle import cheetah_view, redirect, request, route, static_file
6 from m_librarian.db import Author, Book
7 from m_librarian.search import search_authors
11 @cheetah_view('index.tmpl')
16 @route('/search_authors', method='GET')
17 def _search_authors():
18 return redirect('/search_authors/')
21 @route('/search_authors/', method='GET')
22 @cheetah_view('search_authors.tmpl')
23 def search_authors_get():
28 if isinstance(value, bytes):
29 return value.decode('utf-8')
33 def _guess_case_sensitivity(value):
34 return not value.islower()
37 @route('/search_authors/', method='POST')
38 @cheetah_view('list_authors.tmpl')
39 def search_authors_post():
40 value = request.forms.get('search_authors')
42 return redirect('/search_authors/')
44 search_type = request.forms.get('search_type')
47 case_sensitive = request.forms.get('case_sensitive')
48 if case_sensitive is None:
49 case_sensitive = _guess_case_sensitivity(value)
51 CONCAT(Author.q.surname, ' ', Author.q.name, ' ', Author.q.misc_name),
54 authors = search_authors(search_type, case_sensitive, {}, expressions,
55 orderBy=('surname', 'name', 'misc_name'))
57 'authors': list(authors),
58 'search_authors': value,
59 'search_type': search_type,
60 'case_sensitive': case_sensitive,
64 @route('/books-by-author/<id:int>/', method='GET')
65 @cheetah_view('books_by_author.tmpl')
66 def books_by_author(id):
68 'author': Author.get(id),
70 Book.j.authors & (Author.q.id == id),
71 orderBy=['series', 'ser_no', 'title'],
76 @route('/static/<filename:path>')
77 def send_static(filename):
79 filename, root=os.path.join(
80 os.path.dirname(__file__),