volume and imprint for isbn/csv
[wolnelektury.git] / src / catalogue / management / commands / eisbn_csv.py
index ec13332..3c46ea6 100644 (file)
@@ -32,11 +32,42 @@ PRODUCT_FORMS_2 = {
     'MOBI': 'E127',
 }
 
+VOLUME_NUMBERS = {
+    u'pierwszy': 1,
+    u'drugi': 2,
+    u'trzeci': 3,
+    u'czwarty': 4,
+    u'piąty': 5,
+    u'szósty': 6,
+    u'I': 1,
+    u'II': 2,
+    u'III': 3,
+    u'IV': 4,
+    u'V': 5,
+    u'VI': 6,
+}
+
 
 def is_institution(name):
     return name.startswith(u'Zgromadzenie Ogólne')
 
 
+VOLUME_SEPARATOR = ', tom '
+
+
+def get_volume(title):
+    if VOLUME_SEPARATOR not in title:
+        return title, ''
+    else:
+        vol_idx = title.index(VOLUME_SEPARATOR)
+        stripped = title[:vol_idx]
+        vol_name = title[vol_idx + len(VOLUME_SEPARATOR):]
+        if vol_name in VOLUME_NUMBERS:
+            return stripped, VOLUME_NUMBERS[vol_name]
+        else:
+            return title, ''
+
+
 class Command(BaseCommand):
     @staticmethod
     def dc_values(desc, tag):
@@ -48,11 +79,11 @@ class Command(BaseCommand):
             desc = book.wldocument().edoc.find('.//' + RDFNS('Description'))
             formats = FORMATS_WITH_CHILDREN if book.children.exists() else FORMATS
             for file_format in formats:
-                imprint = u'Fundacja Nowoczesna Polska'
-                title = book.title
+                # imprint = u'Fundacja Nowoczesna Polska'
+                imprint = '; '.join(self.dc_values(desc, 'publisher'))
+                title, volume = get_volume(book.title)
                 subtitle = ''
                 year = ''
-                volume = ''
                 publication_date = localtime(book.created_at).date().isoformat()
                 info_date = publication_date
                 author = '; '.join(self.dc_values(desc, 'creator'))