1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from oai.handlers import Catalogue, NS_DCTERMS, nsdcterms
5 from oaipmh.server import ServerBase, NS_OAIDC, NS_DC, NS_XSI, nsoaidc, nsdc
6 from oaipmh.metadata import MetadataRegistry
7 from django.http import HttpResponse
8 from django.utils.functional import SimpleLazyObject
9 from lxml.etree import SubElement
13 #ns_map = {'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI }
16 def fbc_oai_dc_writer(element, metadata):
17 """FBC notified us that original writer does not output all necessary namespace declarations.
19 e_dc = SubElement(element, nsoaidc('dc'),
20 nsmap={'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI})
21 e_dc.set('{%s}schemaLocation' % NS_XSI,
22 '%s http://www.openarchives.org/OAI/2.0/oai_dc.xsd' % NS_OAIDC)
23 map = metadata.getMap()
25 'title', 'creator', 'subject', 'description', 'publisher',
26 'contributor', 'date', 'type', 'format', 'identifier',
27 'source', 'language', 'relation', 'coverage', 'rights',
29 for value in map.get(name, []):
30 e = SubElement(e_dc, nsdc(name))
34 def qdc_writer(element, metadata):
35 """FBC notified us that original writer does not output all necessary namespace declarations.
37 nsmap = {'oai_dc': NS_OAIDC, 'dc': NS_DC, 'xsi': NS_XSI, 'dcterms': NS_DCTERMS}
38 map = metadata.getMap()
40 'title', 'creator', 'subject', 'description', 'publisher',
41 'contributor', 'date', 'type', 'format', 'identifier',
42 'source', 'language', 'relation', 'coverage', 'rights',
44 for value in map.get(name, []):
45 e = SubElement(element, nsdc(name), nsmap=nsmap)
48 for name in ['hasPart', 'isPartOf']:
49 for value in map.get(name, []):
50 e = SubElement(element, nsdcterms(name), nsmap=nsmap)
55 metadata_registry = MetadataRegistry()
56 metadata_registry.registerWriter('oai_dc', fbc_oai_dc_writer)
57 metadata_registry.registerWriter('qdc', qdc_writer)
60 server = SimpleLazyObject(lambda:
61 ServerBase(Catalogue(metadata_registry), metadata_registry,
67 resp = server.handleRequest(request.GET)
68 return HttpResponse(resp, content_type='application/xml')