def open_access_link(self, lpdm): url = cdnify(lpdm.resource.url, Configuration.cdns()) 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 = OPDSFeed.makeelement("{%s}availability" % OPDSFeed.OPDS_NS, status="available") link_tag.append(always_available) return link_tag
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
def borrow_link(self, identifier, borrow_mechanism, fulfillment_mechanisms): if borrow_mechanism: # Following this link will both borrow the book and set # its delivery mechanism. mechanism_id = borrow_mechanism.delivery_mechanism.id else: # Following this link will borrow the book but not set # its delivery mechanism. mechanism_id = None borrow_url = self.url_for( "borrow", identifier_type=identifier.type, identifier=identifier.identifier, mechanism_id=mechanism_id, library_short_name=self.library.short_name, _external=True) rel = OPDSFeed.BORROW_REL borrow_link = AcquisitionFeed.link( rel=rel, href=borrow_url, type=OPDSFeed.ENTRY_TYPE ) indirect_acquisitions = [] for lpdm in fulfillment_mechanisms: # We have information about one or more delivery # mechanisms that will be available at the point of # fulfillment. To the extent possible, put information # about these mechanisms into the <link> tag as # <opds:indirectAcquisition> tags. # These are the formats mentioned in the indirect # acquisition. format_types = AcquisitionFeed.format_types(lpdm.delivery_mechanism) # If we can borrow this book, add this delivery mechanism # to the borrow link as an <opds:indirectAcquisition>. if format_types: indirect_acquisition = AcquisitionFeed.indirect_acquisition( format_types ) indirect_acquisitions.append(indirect_acquisition) if not indirect_acquisitions: raise UnfulfillableWork() borrow_link.extend(indirect_acquisitions) return borrow_link
def borrow_link(self, data_source_name, identifier, borrow_mechanism, fulfillment_mechanisms): if borrow_mechanism: # Following this link will both borrow the book and set # its delivery mechanism. mechanism_id = borrow_mechanism.delivery_mechanism.id else: # Following this link will borrow the book but not set # its delivery mechanism. mechanism_id = None borrow_url = self.url_for( "borrow", data_source=data_source_name, identifier_type=identifier.type, identifier=identifier.identifier, mechanism_id=mechanism_id, _external=True) rel = OPDSFeed.BORROW_REL borrow_link = AcquisitionFeed.link( rel=rel, href=borrow_url, type=OPDSFeed.ENTRY_TYPE ) for lpdm in fulfillment_mechanisms: # We have information about one or more delivery # mechanisms that will be available at the point of # fulfillment. To the extent possible, put information # about these mechanisms into the <link> tag as # <opds:indirectAcquisition> tags. # These are the formats mentioned in the indirect # acquisition. format_types = AcquisitionFeed.format_types(lpdm.delivery_mechanism) # If we can borrow this book, add this delivery mechanism # to the borrow link as an <opds:indirectAcquisition>. if format_types: indirect_acquisition = AcquisitionFeed.indirect_acquisition( format_types ) borrow_link.append(indirect_acquisition) return borrow_link