]> git.phdru.name Git - m_librarian.git/commitdiff
Process author names
authorOleg Broytman <phd@phdru.name>
Thu, 11 Feb 2016 21:37:27 +0000 (00:37 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 11 Feb 2016 21:53:03 +0000 (00:53 +0300)
m_librarian/db.py
m_librarian/inp.py

index 6e08204acfcdac30da1ec9790b2132d9e7d8df14..ba091f3442286186c4cacb4de619f51078cb25cf 100755 (executable)
@@ -2,7 +2,7 @@
 
 __all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language',
            'AuthorBook', 'BookGenre',
-           'init_db', 'insert_name', 'update_counters',
+           'init_db', 'insert_name', 'insert_author', 'update_counters',
            ]
 
 import os
@@ -157,6 +157,14 @@ def insert_name(table, name, **kw):
         return table(name=name, count=0, **kw)
 
 
+def insert_author(surname, name, misc_name):
+    try:
+        return Author.full_name_idx.get(
+            surname=surname, name=name, misc_name=misc_name)
+    except SQLObjectNotFound:
+        return Author(surname=surname, name=name, misc_name=misc_name, count=0)
+
+
 def update_counters():
     for author in Author.select():
         author.count = len(author.books)
index d4e6cc1ff730f09f3dc403bdb213e928da4dbd54..56f85e4d1dcdfb4561fe0ac08cc4d364c291f25a 100644 (file)
@@ -4,7 +4,8 @@ __all__ = ['import_inpx']
 import os
 from zipfile import ZipFile
 from sqlobject import sqlhub, SQLObjectNotFound
-from .db import Author, Book, Extension, Genre, Language, insert_name
+from .db import Author, Book, Extension, Genre, Language, \
+    insert_name, insert_author
 
 
 EOT = chr(4)  # INP field separator
@@ -46,7 +47,17 @@ def import_inp_line(archive, parts):
                 language=language_row)
     for author in authors.split(':'):
         if author:
-            author_row = insert_name(Author, author)
+            alist = author.split(',', 2)
+            surname = alist[0]
+            if len(alist) > 1:
+                name = alist[1]
+                if len(alist) == 3:
+                    misc_name = alist[2]
+                else:
+                    misc_name = ''
+            else:
+                name = misc_name = ''
+            author_row = insert_author(surname, name, misc_name)
             book.addAuthor(author_row)
     for genre in genres.split(':'):
         if genre: