Added setting extra_info on Book models during import.
[wolnelektury.git] / lib / librarian / dcparser.py
index 9281325..8542553 100644 (file)
@@ -45,7 +45,7 @@ def str_to_unicode(value, previous):
 def str_to_unicode_list(value, previous):
     if previous is None:
         previous = []
-    previous.append(str_to_unicode(value))
+    previous.append(str_to_unicode(value, None))
     return previous
 
 
@@ -76,7 +76,7 @@ def str_to_date(value, previous):
 # ==========
 class ParseError(Exception):
     def __init__(self, message):
-        super(self, Exception).__init__(message)
+        super(ParseError, self).__init__(message)
 
 
 class XMLNamespace(object):
@@ -165,6 +165,17 @@ class BookInfo(object):
         
         return unicode(etree.tostring(root, 'utf-8'), 'utf-8')
 
+    def to_dict(self):
+        etree._namespace_map[str(self.RDF)] = 'rdf'
+        etree._namespace_map[str(self.DC)] = 'dc'
+        
+        result = {}        
+        for tag, (attribute, converter) in self.mapping.iteritems():
+            if hasattr(self, attribute):
+                result[attribute] = unicode(getattr(self, attribute))
+        
+        return result
+
 
 def parse(file_name):
     return BookInfo.from_file(file_name)