X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/5938bc78f11ebad067eae86f51b4f5243003f946..6c0f71f581d5b8d9a519a6645f571f54b38afca8:/librarian/dcparser.py?ds=inline diff --git a/librarian/dcparser.py b/librarian/dcparser.py index 26f2a0c..9faffe8 100644 --- a/librarian/dcparser.py +++ b/librarian/dcparser.py @@ -38,9 +38,17 @@ class Person(object): names = [ name for name in parts[1].split() if len(name) ] # all non-whitespace tokens return cls(surname, *names) + def readable(self): + return u" ".join(self.first_names + (self.last_name,)) + def __eq__(self, right): return self.last_name == right.last_name and self.first_names == right.first_names + def __cmp__(self, other): + return cmp((self.last_name, self.first_names), (other.last_name, other.first_names)) + + def __hash__(self): + return hash((self.last_name, self.first_names)) def __unicode__(self): if len(self.first_names) > 0: @@ -88,7 +96,7 @@ class Field(object): return val return [ self.validator(v) if v is not None else v for v in val ] elif len(val) > 1: - raise ValidationError("Mulitply values not allowed for field '%s'" % self.uri) + raise ValidationError("Multiple values not allowed for field '%s'" % self.uri) elif len(val) == 0: raise ValidationError("Field %s has no value to assign. Check your defaults." % self.uri) else: @@ -134,6 +142,7 @@ class BookInfo(object): Field( DCNS('relation.hasPart'), 'parts', multiple=True, required=False), Field( DCNS('rights.license'), 'license', required=False), Field( DCNS('rights'), 'license_description'), + Field( DCNS('description'), 'description', required=False), ) @property @@ -259,7 +268,8 @@ class BookInfo(object): if len(v) == 0: continue for x in v: e = etree.Element(field.uri) - e.text = unicode(x) + if x is not None: + e.text = unicode(x) description.append(e) else: e = etree.Element(field.uri) @@ -279,7 +289,7 @@ class BookInfo(object): if v is not None: if field.multiple: if len(v) == 0: continue - v = [ unicode(x) for x in v if v is not None ] + v = [ unicode(x) for x in v if x is not None ] else: v = unicode(v) @@ -295,7 +305,7 @@ class BookInfo(object): if v is not None: if field.multiple: if len(v) == 0: continue - v = [ unicode(x) for x in v if v is not None ] + v = [ unicode(x) for x in v if x is not None ] else: v = unicode(v) result[field.name] = v