Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Jun 6, 2018
2 parents 730074a + af2a241 commit f0a228e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
CHANGELOG
=========

1.0.1
-----

* bugfix: use license text label from local manifest data if possible;
avoids issue with current logic for retrieving labels from
rightsstatements.org causing a 500 error.

1.0
---

Expand Down
2 changes: 1 addition & 1 deletion derrida/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version_info__ = (1, 0, 0, None)
__version_info__ = (1, 0, 1, None)


# Dot-connect all but the last. Last is dash-connected if not None.
Expand Down
9 changes: 9 additions & 0 deletions derrida/books/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def test_instance_detail_view(self, mockrequests):
response = self.client.get(detail_view_url)
assert 'license_text' not in response.context

# fixture with edm_rights in manifest extra data
saussure = Instance.objects.get(slug__contains='saussure-cours-de-linguistique')
mockrequests.reset_mock()
response = self.client.get(saussure.get_absolute_url())
# license label from edm rights
assert response.context['license_text'] == 'In Copyright'
# no need to load externally when found in manifest data
mockrequests.get.assert_not_called()


@pytest.mark.haystack
def test_instance_list_view(self):
Expand Down
34 changes: 24 additions & 10 deletions derrida/books/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,30 @@ def get_context_data(self, *args, **kwargs):
'''Insert manifest license data into template context.'''
context_data = super(InstanceDetailView, self).get_context_data()
instance = context_data['object']
license_url = instance.digital_edition.license
if license_url:
data_url = license_url.split('?')[0].replace('vocab', 'data')
response = requests.get(data_url)
if response.status_code == 200:
# This should be safe for all rightsstatments.org
# prefLabels as they seem to be setting English as their
# default using @ notation.
context_data['license_text'] = \
response.json()['prefLabel']['@value']
license_text = None
# PUL seeAlso data contains an "edm_rights" section with
# a label for the rights statement. Use that if possible
for data in instance.digital_edition.extra_data.values():
if 'edm_rights' in data:
license_text = data['edm_rights']['pref_label']
break

# if license text not found, look up label based on license uri
if not license_text:
license_url = instance.digital_edition.license
if license_url:
# NOTE: url logic is specific to rightsstatements.org
data_url = license_url.replace('vocab', 'data')
response = requests.get(data_url)
if response.status_code == 200:
# This should be safe for all rightsstatments.org
# prefLabels as they seem to be setting English as their
# default using @ notation.
license_text = response.json()['prefLabel']['@value']

if license_text:
context_data['license_text'] = license_text

return context_data


Expand Down

0 comments on commit f0a228e

Please sign in to comment.