From 868f9fd045fa1b4aecc328f818017ecbc91533c4 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 6 Jun 2016 22:07:40 +0300 Subject: [PATCH 1/1] Refactor author.filename --- m_librarian/db.py | 6 ++++++ scripts/ml-search.py | 9 ++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/m_librarian/db.py b/m_librarian/db.py index 8786a46..e7eea99 100755 --- a/m_librarian/db.py +++ b/m_librarian/db.py @@ -20,6 +20,12 @@ class Author(SQLObject): books = RelatedJoin('Book', otherColumn='book_id', intermediateTable='author_book', createRelatedTable=False) + + @property + def fullname(self): + fullnames = filter(None, (self.surname, self.name, self.misc_name)) + return ' '.join(fullnames) + full_name_idx = DatabaseIndex(surname, name, misc_name, unique=True) count_idx = DatabaseIndex(count) diff --git a/scripts/ml-search.py b/scripts/ml-search.py index b257084..0d995e5 100755 --- a/scripts/ml-search.py +++ b/scripts/ml-search.py @@ -60,9 +60,7 @@ def _search_authors(case_sensitive, search_type, args): return count = 0 for author in authors: - names = filter(None, (author.surname, author.name, author.misc_name)) - fullname = u' '.join(names) - print fullname.encode(default_encoding), \ + print author.fullname.encode(default_encoding), \ (u"(%s: %d)" % (_('books'), author.count))\ .encode(default_encoding), if args.verbose >= 1: @@ -158,10 +156,7 @@ def _search_books(case_sensitive, search_type, args): if args.verbose >= 1: print " ", _("Author(s)").encode(default_encoding), ":", for author in book.authors: - names = filter(None, - (author.surname, author.name, author.misc_name)) - fullname = u' '.join(names) - print fullname.encode(default_encoding), + print author.fullname.encode(default_encoding), print print " ", _("Genre(s)").encode(default_encoding), ":", for genre in book.genres: -- 2.39.2