From: Oleg Broytman Date: Tue, 24 May 2016 21:59:10 +0000 (+0300) Subject: Search books by genre's name and title X-Git-Tag: 0.0.7~1 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=aec9a91be72b26000e2cba53a6e3e5029d43a469;p=m_librarian.git Search books by genre's name and title --- diff --git a/docs-ru/command_line.rst b/docs-ru/command_line.rst index 202494c..945b818 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] [--surname name] [--name name] [--misc-name name] [--fullname name] [-e ext] [-l lang] + ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [--surname name] [--name name] [--misc-name name] [--fullname name] [--gname name] [--gtitle title] [-e ext] [-l lang] Искать и печатать список книг по заголовку, серии, архиву, имени файла. @@ -118,6 +118,8 @@ ml-search.py --misc-name misc. name Искать по доп. имени автора --fullname name Искать по полному имени автора -e, --ext ext Искать по расширению имени файла + --gname name Искать по названию жанра + --gtitle title Искать по заголовку жанра -l, --lang lang Искать по языку По умолчанию программы выводит список заголовков найденных книг. При diff --git a/docs/command_line.rst b/docs/command_line.rst index 1739afc..0289a1e 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] [--surname name] [--name name] [--misc-name name] [--fullname name] [-e ext] [-l lang] + ml-search.py [-i/-I] [-t/-s/-f] books [-t title] [-s series] [-a archive] [-f file] [-d] [--surname name] [--name name] [--misc-name name] [--fullname name] [-e ext] [--gname name] [--gtitle title] [-l lang] Search and print a list of books by title, series, archive or file name. @@ -116,6 +116,8 @@ Options:: --misc-name misc. name Search by author's misc. name --fullname name Search by author's full name -e, --ext ext Search by file extension + --gname name Search by genre's name + --gtitle title Search by genre's title -l, --lang lang Search by language By default the program prints only titles of the found book. With one diff --git a/scripts/ml-search.py b/scripts/ml-search.py index db57f2b..5a5ff96 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, Language, open_db +from m_librarian.db import Author, Book, Extension, Genre, Language, open_db from m_librarian.search import mk_search_conditions, \ search_authors, search_books, \ search_extensions, search_genres, search_languages @@ -63,7 +63,8 @@ def _search_books(case_sensitive, search_type, args): if case_sensitive is None: test_values = values.copy() test_values.update(_get_values(args, 'surname', 'name', 'misc_name', - 'fullname', 'ext', 'lang')) + 'fullname', 'ext', 'gname', 'gtitle', + 'lang')) case_sensitive = _guess_case_sensitivity(test_values) avalues = _get_values(args, 'surname', 'name', 'misc_name', 'fullname') if avalues: @@ -90,6 +91,16 @@ def _search_books(case_sensitive, search_type, args): Extension, search_type, case_sensitive, {'name': args.ext}) join_expressions.extend(conditions) + gvalues = {} + for column in 'name', 'title': + value = getattr(args, 'g' + column) + if value: + gvalues[column] = unicode(value, default_encoding) + if gvalues: + join_expressions.append(Book.j.genres) + conditions = mk_search_conditions( + Genre, search_type, case_sensitive, gvalues) + join_expressions.extend(conditions) if args.lang: join_expressions.append(Book.j.language) conditions = mk_search_conditions( @@ -203,6 +214,8 @@ if __name__ == '__main__': parser.add_argument('--misc-name', help='search by author\'s misc. name') parser.add_argument('--fullname', help='search by author\'s full name') parser.add_argument('-e', '--ext', help='search by file extension') + parser.add_argument('--gname', help='search by genre\'s name') + parser.add_argument('--gtitle', help='search by genre\'s title') parser.add_argument('-l', '--lang', help='search by language') parser.set_defaults(func=_search_books)