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