X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/53acb1f3e125b31e3c0837a67bf0a4a9a29e4548..4077ffb3cbd868df95239898563508b64e6d6ecf:/librarian/dcparser.py diff --git a/librarian/dcparser.py b/librarian/dcparser.py index 9faffe8..992029e 100644 --- a/librarian/dcparser.py +++ b/librarian/dcparser.py @@ -7,7 +7,8 @@ from xml.parsers.expat import ExpatError from datetime import date import time -from librarian import ValidationError, NoDublinCore, ParseError, DCNS, RDFNS +from librarian import (ValidationError, NoDublinCore, ParseError, DCNS, RDFNS, + WLURI) import lxml.etree as etree # ElementTree API using libxml2 from lxml.etree import XMLSyntaxError @@ -127,6 +128,8 @@ class BookInfo(object): Field( DCNS('subject.period'), 'epochs', salias='epoch', multiple=True), Field( DCNS('subject.type'), 'kinds', salias='kind', multiple=True), Field( DCNS('subject.genre'), 'genres', salias='genre', multiple=True), + Field( DCNS('audience'), 'audiences', salias='audience', multiple=True, + required=False), Field( DCNS('date'), 'created_at', as_date), Field( DCNS('date.pd'), 'released_to_public_domain_at', as_date, required=False), Field( DCNS('contributor.editor'), 'editors', \ @@ -138,17 +141,14 @@ class BookInfo(object): Field( DCNS('publisher'), 'publisher'), Field( DCNS('source'), 'source_name', required=False), Field( DCNS('source.URL'), 'source_url', required=False), - Field( DCNS('identifier.url'), 'url'), - Field( DCNS('relation.hasPart'), 'parts', multiple=True, required=False), + Field( DCNS('identifier.url'), 'url', WLURI), + Field( DCNS('relation.hasPart'), 'parts', WLURI, multiple=True, required=False), Field( DCNS('rights.license'), 'license', required=False), Field( DCNS('rights'), 'license_description'), + Field( DCNS('language'), 'language'), Field( DCNS('description'), 'description', required=False), ) - @property - def slug(self): - return self.url.rsplit('/', 1)[1] - @classmethod def from_string(cls, xml): from StringIO import StringIO @@ -212,6 +212,11 @@ class BookInfo(object): self.fmap[field.name] = field if field.salias: self.fmap[field.salias] = field + self.validate() + + def validate(self): + self.url.validate_language(self.language) + def __getattribute__(self, name): try: field = object.__getattribute__(self, 'fmap')[name]