]> git.phdru.name Git - m_librarian.git/commitdiff
Refactor author.filename
authorOleg Broytman <phd@phdru.name>
Mon, 6 Jun 2016 19:07:40 +0000 (22:07 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 6 Jun 2016 19:07:40 +0000 (22:07 +0300)
m_librarian/db.py
scripts/ml-search.py

index 8786a461b8c69e4dd6fcfd032abce9054e5d7ddc..e7eea99560eadf289c8beab669c0043fa3cfdaa7 100755 (executable)
@@ -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)
 
index b257084a749d03a487f2f0889b656b57639d35dc..0d995e505f1bd359a7b3b134e5861aa6c86fbcca 100755 (executable)
@@ -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: