From 900d4e36f7ea51280e43ecf52c2412b94083ca76 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 23 May 2016 23:20:31 +0300 Subject: [PATCH] Refactoring: allow expressions to be None --- m_librarian/search.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/m_librarian/search.py b/m_librarian/search.py index 300e2a6..5b289f0 100644 --- a/m_librarian/search.py +++ b/m_librarian/search.py @@ -11,6 +11,8 @@ from .db import Author, Book, Extension, Genre, Language def _mk_search_conditions_with_operator(table, case_sensitive, comparison_op, values, expressions): + if expressions is None: + expressions = [] _expressions = [] if case_sensitive: for column, value in values.items(): @@ -38,40 +40,40 @@ _search_conditions_dict = { def mk_search_conditions(table, search_type, case_sensitive, values, - expressions): + expressions=None): return _mk_search_conditions_with_operator( table, case_sensitive, _search_conditions_dict[search_type], values, expressions) def _search(table, search_type, case_sensitive, values, - expressions, orderBy=None): + expressions=None, orderBy=None): conditions = mk_search_conditions( - table, search_type, case_sensitive, values, expressions) + table, search_type, case_sensitive, values, expressions=expressions) return table.select(AND(*conditions), orderBy=orderBy) def search_authors(search_type, case_sensitive, values, - expressions, orderBy=None): + expressions=None, orderBy=None): return _search(Author, search_type, case_sensitive, values, - expressions, orderBy) + expressions=None, orderBy=orderBy) def search_books(search_type, case_sensitive, values, orderBy=None): return _search(Book, search_type, case_sensitive, values, - [], orderBy) + orderBy=orderBy) def search_extensions(search_type, case_sensitive, values, orderBy=None): return _search(Extension, search_type, case_sensitive, values, - [], orderBy) + orderBy=orderBy) def search_genres(search_type, case_sensitive, values, orderBy=None): return _search(Genre, search_type, case_sensitive, values, - [], orderBy) + orderBy=orderBy) def search_languages(search_type, case_sensitive, values, orderBy=None): return _search(Language, search_type, case_sensitive, values, - [], orderBy) + orderBy=orderBy) -- 2.39.5