From 87957f1a6b6e55664837f6493981094868b76cc1 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 23 May 2016 23:27:54 +0300 Subject: [PATCH] Search books by language --- docs-ru/command_line.rst | 3 ++- docs/command_line.rst | 3 ++- scripts/ml-search.py | 11 +++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs-ru/command_line.rst b/docs-ru/command_line.rst index 4cb958f..640607d 100644 --- a/docs-ru/command_line.rst +++ b/docs-ru/command_line.rst @@ -100,7 +100,7 @@ ml-search.py Использование:: - ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [-e ext] + ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [-e ext] [-l lang] Искать и печатать список книг по заголовку, серии, архиву, имени файла. @@ -114,6 +114,7 @@ ml-search.py повторите эту опцию несколько раз, чтобы получить ещё больше деталей -e, --ext ext Искать по расширению имени файла + -l, --lang lang Искать по языку По умолчанию программы выводит список заголовков найденных книг. При использовании опции `-d` также выводится список авторов и жанров, а diff --git a/docs/command_line.rst b/docs/command_line.rst index 99fb72e..837a415 100644 --- a/docs/command_line.rst +++ b/docs/command_line.rst @@ -99,7 +99,7 @@ Book search Usage:: - ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [-e ext] + ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [-e ext] [-l lang] Search and print a list of books by title, series, archive or file name. @@ -112,6 +112,7 @@ Options:: -d, --details Output more details about books; repeat for even more details -e, --ext ext Search by file extension + -l, --lang lang Search by language By default the program prints only titles of the found book. With one option `-d` it also prints the list of authors and genres, and also diff --git a/scripts/ml-search.py b/scripts/ml-search.py index b5b34c4..4757628 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -5,7 +5,7 @@ import sys from sqlobject.sqlbuilder import CONCAT from m_lib.defenc import default_encoding -from m_librarian.db import Author, Book, Extension, open_db +from m_librarian.db import Author, Book, Extension, Language, open_db from m_librarian.search import mk_search_conditions, \ search_authors, search_books, \ search_extensions, search_genres, search_languages @@ -61,7 +61,7 @@ def _search_books(case_sensitive, search_type, args): values[column] = unicode(value, default_encoding) if case_sensitive is None: test_values = values.copy() - for column in 'ext', : + for column in 'ext', 'lang': value = getattr(args, column) if value: test_values[column] = unicode(value, default_encoding) @@ -72,6 +72,12 @@ def _search_books(case_sensitive, search_type, args): Extension, search_type, case_sensitive, {'name': args.ext}) join_expressions.extend(conditions) + if args.lang: + join_expressions.append(Book.j.language) + conditions = mk_search_conditions( + Language, search_type, case_sensitive, + {'name': args.lang}) + join_expressions.extend(conditions) for book in search_books(search_type, case_sensitive, values, join_expressions, orderBy=('series', 'ser_no', 'title')): @@ -179,6 +185,7 @@ if __name__ == '__main__': help='output more details about books; ' 'repeat for even more details') parser.add_argument('-e', '--ext', help='search by file extension') + parser.add_argument('-l', '--lang', help='search by language') parser.set_defaults(func=_search_books) parser = subparsers.add_parser('ext', help='Search extensions') -- 2.39.5