def fulfill_open_access(self, licensepool, delivery_mechanism): # Keep track of a default way to fulfill this loan in case the # patron's desired delivery mechanism isn't available. fulfillment = None for lpdm in licensepool.delivery_mechanisms: if not (lpdm.resource and lpdm.resource.representation and lpdm.resource.representation.url): # We don't actually know how to deliver this # allegedly open-access book. continue if lpdm.delivery_mechanism == delivery_mechanism: # We found it! This is how the patron wants # the book to be delivered. fulfillment = lpdm break elif not fulfillment: # This will do in a pinch. fulfillment = lpdm if not fulfillment: # There is just no way to fulfill this loan. raise NoOpenAccessDownload() rep = fulfillment.resource.representation cdn_host = Configuration.cdn_host(Configuration.CDN_OPEN_ACCESS_CONTENT) content_link = cdnify(rep.url, cdn_host) media_type = rep.media_type return FulfillmentInfo( identifier_type=licensepool.identifier.type, identifier=licensepool.identifier.identifier, content_link=content_link, content_type=media_type, content=None, content_expires=None )
def open_access_link(self, lpdm): cdn_host = Configuration.cdn_host(Configuration.CDN_OPEN_ACCESS_CONTENT) url = cdnify(lpdm.resource.url, cdn_host) kw = dict(rel=OPDSFeed.OPEN_ACCESS_REL, href=url) rep = lpdm.resource.representation if rep and rep.media_type: kw['type'] = rep.media_type link_tag = AcquisitionFeed.link(**kw) always_available = E._makeelement( "{%s}availability" % opds_ns, status="available" ) link_tag.append(always_available) return link_tag