Skip to content

Commit ca033a1

Browse files
authored
Merge pull request #1910 from NYPL-Simplified/SMA-523-add-open-access-until-date
Sma 523 add open access until date
2 parents 28b876a + b579692 commit ca033a1

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

api/opds.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def open_access_link(self, pool, lpdm):
425425
always_available = OPDSFeed.makeelement(
426426
"{%s}availability" % OPDSFeed.OPDS_NS, status="available"
427427
)
428+
428429
link_tag.append(always_available)
429430
return link_tag
430431

@@ -1130,7 +1131,7 @@ def fulfill_link(self, license_pool, active_loan, delivery_mechanism,
11301131
active_loan=active_loan
11311132
)
11321133

1133-
children = AcquisitionFeed.license_tags(license_pool, active_loan, None)
1134+
children = AcquisitionFeed.license_tags(license_pool, active_loan, None, rel=rel, library=self.library)
11341135
link_tag.extend(children)
11351136

11361137
children = self.drm_device_registration_tags(

core/opds.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ def indirect_acquisition(cls, indirect_types):
16501650
return top_level_parent
16511651

16521652
@classmethod
1653-
def license_tags(cls, license_pool, loan, hold):
1653+
def license_tags(cls, license_pool, loan, hold, rel=None, library=None):
16541654
# Generate a list of licensing tags. These should be inserted
16551655
# into a <link> tag.
16561656
tags = []
@@ -1688,10 +1688,16 @@ def license_tags(cls, license_pool, loan, hold):
16881688
else:
16891689
status = 'reserved'
16901690
since = hold.start
1691-
elif (license_pool.open_access or license_pool.unlimited_access or license_pool.self_hosted or (
1691+
elif (license_pool.open_access or rel == OPDSFeed.OPEN_ACCESS_REL):
1692+
status = 'available'
1693+
1694+
default_loan_period = collection.default_loan_period(library) if library else collection.STANDARD_DEFAULT_LOAN_PERIOD
1695+
1696+
since = license_pool.availability_time
1697+
until = datetime.datetime.utcnow() + datetime.timedelta(days=default_loan_period)
1698+
elif (license_pool.unlimited_access or license_pool.self_hosted or (
16921699
license_pool.licenses_available > 0 and
1693-
license_pool.licenses_owned > 0)
1694-
):
1700+
license_pool.licenses_owned > 0)):
16951701
status = 'available'
16961702
else:
16971703
status='unavailable'

core/tests/test_opds.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,33 @@ def test_license_tags_show_self_hosted_books(self):
16251625
assert 'status' in tags[0].attrib
16261626
assert 'available' == tags[0].attrib['status']
16271627

1628+
def test_license_tags_open_access(self):
1629+
# Arrange
1630+
edition, pool = self._edition(with_license_pool=True)
1631+
pool.open_access = True
1632+
pool.self_hosted = False
1633+
pool.unlimited_access = False
1634+
creation_time = datetime.datetime.utcnow()
1635+
1636+
# Act
1637+
tags = AcquisitionFeed.license_tags(
1638+
pool, None, None
1639+
)
1640+
1641+
# Assert
1642+
assert 1 == len(tags)
1643+
1644+
[tag] = tags
1645+
1646+
assert ('status' in tag.attrib) == True
1647+
assert 'available' == tag.attrib['status']
1648+
assert 'since' in tag.attrib
1649+
assert tag.attrib['since'] == pool.availability_time.strftime('%Y-%m-%dT%H:%M:%S+00:00')
1650+
assert 'until' in tag.attrib
1651+
assert tag.attrib['until'] == (creation_time + datetime.timedelta(days=21)).strftime('%Y-%m-%dT%H:%M:%SZ')
1652+
assert ('holds' in tag.attrib) == False
1653+
assert ('copies' in tag.attrib) == False
1654+
16281655
def test_single_entry(self):
16291656

16301657
# Here's a Work with two LicensePools.

0 commit comments

Comments
 (0)