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

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Jun 22, 2018
2 parents f0a228e + e3bec0b commit 190d175
Show file tree
Hide file tree
Showing 69 changed files with 300 additions and 10,487 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
CHANGELOG
=========

1.1
---

* Add license to README and document Princeton docket # for permissions
* Adjust homepage styles for mobile
* Set content pages to use the same style as Outwork posts
* Display page description as lead text if not auto-generated
* Refine license text logic to use label from manifest if possible;
include on both library detail and canvas detail pages
* Revise banner images metadata preview handling
* Remove static urls for testing 404/500 pages
* Don't display "None" on library book detail page for no publication date
* Update deploy scripts with missing environment variables, and adjust
logic for deploy symlink and previous/current symlinks
* bugfix: 404 on attempt to get image for a work instance with no
digital edition
* bugfix: Correct reference card thumbnail display and instance title logic


1.0.1
-----

Expand Down
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ contains the most recent release, and work in progress will be on the develop br
Pull requests should be made against develop.


License
-------

**derrida-django** is distributed under the Apache 2.0 License.

©2018 Trustees of Princeton University. Permission granted via
Princeton Docket #18-3472-1 for distribution online under a standard Open Source
license. Ownership rights transferred to Rebecca Koeser provided software
is distributed online via open source.

Development instructions
------------------------

Expand Down
2 changes: 1 addition & 1 deletion deploy/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ version: '{{ ver.stdout }}'
# Name of the django application (usually 'project' of 'project-django')
djangoapp: derrida
# deploy user HOME
home: "{{ ansible_env.HOME }}"
home: "{{ lookup('env', 'HOME') }}"
44 changes: 30 additions & 14 deletions deploy/roles/golive/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,40 @@
command: migrate
app_path: "{{ deploy }}"
virtualenv: "{{ deploy }}/env"
- name: check for old symlink
- name: Check for current symlink as previous
stat:
path: "/var/www/{{ symlink }}"
register: sym
- name: Copy old symlink path from /var/www to "{{ install_root }}/old"
shell: "cp -d /var/www/{{ symlink }} {{ install_root }}/old"
when: sym.stat.islnk is defined and sym.stat.islnk == True
args:
executable: /bin/bash
- name: New symlink path
path: "{{ install_root }}/current"
register: previous
- name: Set current symlink
file:
src: "{{ deploy }}"
dest: "/var/www/{{ symlink }}"
dest: "{{ install_root }}/current"
state: link
- name: Create courtesy symlink in /srv/www
- name: Register current symlink
stat:
path: "{{ install_root }}/current"
register: current
- name: If current path differs from previous current, update previous
file:
src: "{{ previous.stat.lnk_target }}"
dest: "{{ install_root }}/previous"
state: link
when: previous.stat.exists == True and previous.stat.lnk_source != current.stat.lnk_source
- name: Register there is now a previous symlink
stat:
path: "{{ install_root }}/previous"
register: previous
- name: If previous did not exist (and therefore wasn't reset above), create it with current
# should only trigger on first run of deploy script
file:
src: "{{ deploy }}"
dest: "{{ install_root }}/current"
dest: "{{ install_root }}/previous"
state: link
when: previous.stat.exists == False
- name: Set /var/www/ path to make live
file:
src: "{{ deploy }}"
dest: "/var/www/{{ symlink }}"
state: link

# This makes sure that any server side settings that handle autoconfiguring
Expand All @@ -34,8 +50,8 @@
# Both this and the command below it use the command/shell modules rather than
# the SELinux or Apache modules because we only have limited sudo and rights
# for both these statements
- name: Call restorecon just in case
shell: 'restorecon -R {{ deploy }}'
- name: Call restorecon to set permissions for install_root
shell: '/usr/sbin/restorecon -R {{ install_root }}'
args:
executable: /bin/bash
- name: Restart Apache (scl-httpd24-httpd)
Expand Down
3 changes: 1 addition & 2 deletions deploy/roles/projectrepo/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
- name: Clone settings repository locally
git:
repo: '[email protected]:Princeton-CDH/deployment.git'
# Use lookup here because we're working on the machine running ansible
dest: "{{ lookup('env', 'HOME') }}/.deploy/"
dest: "{{ home }}/.deploy/"
version: 'master'
delegate_to: localhost
- name: Clone the repo if doesn't already exist and make sure it's on gitref
Expand Down
7 changes: 3 additions & 4 deletions deploy/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
# Set environment to use scl rh-python35
environment:
PATH: '/opt/rh/rh-python35/root/usr/bin/:/opt/rh/rh-nodejs6/root/usr/bin:{{ ansible_env.PATH }}'
LD_LIBRARY_PATH: '/opt/rh/rh-python35/root/usr/lib64:/opt/rh/rh-nodejs6/root/usr/lib64:{{ ansible_env.LD_LIBRARY_PATH}}'
PYTHONPATH: '/opt/rh/rh-nodejs6/root/usr/lib/python2.7/site-packages:{{ ansible_env.PATH }}'
LD_LIBRARY_PATH: '/opt/rh/rh-python35/root/usr/lib64:/opt/rh/rh-nodejs6/root/usr/lib64'
PYTHONPATH: '/opt/rh/rh-nodejs6/root/usr/lib/python2.7/site-packages'
roles:
# Creates repo variable names and builds repo
- projectrepo
# Builds a production deploy and sets file permissions correctly
- buildprod
# Makes an emergency database backup, run migrations, and then resets
# symlinks
# Run migrations, and then resets symlinks
- golive
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, 1, None)
__version_info__ = (1, 1, 0, None)


# Dot-connect all but the last. Last is dash-connected if not None.
Expand Down
7 changes: 7 additions & 0 deletions derrida/books/templates/books/instance_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
{% block page-subtitle %}{{ page.meta_title }} ‖ {% endblock %}
{% block nav-title %} {{ page.title }} {% endblock %}

{% block preview_meta %}
{# override preview image #}
{% with page_meta_image='img/banner/[email protected]' twitter_card='summary_large_image' %}
{{ block.super }}
{% endwith %}
{% endblock %}

{% block header_class %}mdl-layout__header--transparent{% endblock %}

{% block page-context-id %}books-list{% endblock %}
Expand Down
3 changes: 2 additions & 1 deletion derrida/books/templates/books/public_canvas_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ <h3 class="gallery-image-view__list-title--bold">Admin Actions</h3>
{# for now, only supports rightsstatments.org licenses (should work for PUL content) #}
{% if instance.digital_edition.license %}
<a href="{{ instance.digital_edition.license }}">
<img class="img" src="{% static 'img/rightsstatements_org/' %}{{ instance.digital_edition.rights_statement_id }}.svg" />
<img class="img" src="{% static 'img/rightsstatements_org/' %}{{ instance.digital_edition.rights_statement_id }}.svg"
alt="{{ instance.digital_edition.license_label }}" />" />
</a>
{% endif %}

Expand Down
7 changes: 7 additions & 0 deletions derrida/books/templates/books/reference_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
{% block page-subtitle %}{{ page.meta_title }} ‖ {% endblock %}
{% block nav-title %} {{ page.title }} {% endblock %}

{% block preview_meta %}
{# override preview image #}
{% with page_meta_image='img/banner/[email protected]' twitter_card='summary_large_image' %}
{{ block.super }}
{% endwith %}
{% endblock %}

{% block header_class %}mdl-layout__header--transparent{% endblock %}

{% block page-context-id %}citations-list{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion derrida/books/templates/components/book-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h3 class="item-term__label">Publisher</h3>

<div class="item-term item-term--inline">
<h3 class="item-term__label">Publication Year</h3>
<p class="item-term__value">{{ book.copyright_year }}</p>
<p class="item-term__value">{{ book.copyright_year|default:'' }}</p>
</div>

{% if book.languages.count %}
Expand Down
2 changes: 1 addition & 1 deletion derrida/books/templates/components/book-license.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if book.digital_edition.license %}
<footer class="item-license">
<img class="item-license__img" src="{% static 'img/rightsstatements_org/' %}{{ book.digital_edition.rights_statement_id }}.svg"
alt="{{ license_text }}" />
alt="{{ book.digital_edition.license_label }}" />
<a class="item-license__link" href="{{ book.digital_edition.license }}"><span class="arrow_icon"></span> Learn More</a>
</footer>
{% endif %}
8 changes: 5 additions & 3 deletions derrida/books/templates/components/citation-list-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
{# instance url for solr reference #}
{% url 'books:detail' slug=reference.instance_slug as instance_url %}
{% firstof reference.instance_digital_edition reference.instance.digital_edition as has_digital_edition %}

<figure class="item__image">
{% if has_digital_edition %}
{# get instance slug from solr result or database model #}
{% firstof reference.instance_slug reference.instance.slug as instance_slug %}
{# NOTE: check for instance.slug first, because instance_slug exists on model but is the *work* slug #}
{% firstof reference.instance.slug reference.instance_slug as instance_slug %}
{# get detail page canvas id from solr or associated intervention #}
{% firstof reference.page_canvas_id reference.interventions.first.canvas.short_id as page_slug %}

Expand All @@ -21,14 +23,14 @@
<a class="item__image-link" href="{% url 'books:canvas-detail' instance_slug page_slug %}">
<img class="img" src="{% url 'books:canvas-image' slug=instance_slug short_id=page_slug mode='smthumb'%}"
srcset="{% url 'books:canvas-image' slug=instance_slug short_id=page_slug mode='smthumb' x='@2x' %} 2x"
alt="View the page containing this reference in {% firstof reference.instance_title instance.display_title %}"/>
alt="View the page containing this reference in {% firstof reference.instance_title reference.instance.display_title %}"/>
</a>
{% else %}
{# if page view is not available, display cover thumbnail and link to book bibliography page #}
<a class="item__image-link item__image-overview" href="{% url 'books:detail' instance_slug %}">
<img class="img" src="{% url 'books:canvas-image' slug=instance_slug short_id='default' mode='smthumb' %}"
srcset="{% url 'books:canvas-image' slug=instance_slug short_id='default' mode='smthumb' x='@2x' %} 2x"
alt="View bibliographic details for {% firstof reference.instance_title instance.display_title %} (detail of this page not available)"/>
alt="View bibliographic details for {% firstof reference.instance_title reference.instance.display_title %} (detail of this page not available)"/>
</a>
{% endif %}
{% else %}
Expand Down
43 changes: 10 additions & 33 deletions derrida/books/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
class TestInstanceViews(TestCase):
fixtures = ['test_instances.json']

@patch('derrida.books.views.requests')
def test_instance_detail_view(self, mockrequests):
def test_instance_detail_view(self):
# get an instance of la_vie
la_vie = Instance.objects.filter(work__primary_title__icontains='la vie').first()
# pass its pk to detail view
Expand All @@ -56,41 +55,12 @@ def test_instance_detail_view(self, mockrequests):
assert 'instance' in response.context
# it should be the copy of la_vie we looked up
assert response.context['instance'] == la_vie
# license lookup not called because there is no license info
assert not mockrequests.called

# add license info to manifest
manif.extra_data.update({
'license': 'http://rightstatements.org/vocab/FOO/v1/',
})
manif.save()
# mock a response from requests with a JSON-LD snippet
# and a successful response code
mockresponse = Mock()
mockrequests.get.return_value = mockresponse
mockresponse.json.return_value = {
'prefLabel': {'@value': 'Foo license'}
}
mockresponse.status_code = 200
response = self.client.get(detail_view_url)
mockrequests.get.assert_called_with('http://rightstatements.org/data/FOO/v1/')
# license text is in context
assert response.context['license_text'] == 'Foo license'
# the alt text exists somewhere in the template
self.assertContains(response, 'alt="Foo license"')
# an error on license lookup causes the license not to be applied
mockresponse.status_code = 403
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()
# license label from edm rights should be set in alt text
self.assertContains(response, 'alt="In Copyright"')


@pytest.mark.haystack
Expand Down Expand Up @@ -983,6 +953,13 @@ def test_get_proxy_url(self, mockrequests):
assert str(imgurl) == \
str(cover.image.size(height=canvasimgview.LARGE_HEIGHT * 2))

# work instance with no digital edition should 404
item.digital_edition = None
item.save()
canvasimgview.kwargs = {'slug': item.slug, 'short_id': 'default'}
with pytest.raises(Http404):
canvasimgview.get_proxy_url(mode='smthumb')

# TODO: test proxyview logic in preserving headers, rewriting
# iiif id to local url, etc

Expand Down
42 changes: 7 additions & 35 deletions derrida/books/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,6 @@ def get_queryset(self):
instances = super(InstanceDetailView, self).get_queryset()
return instances.filter(digital_edition__isnull=False)

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_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


class InstanceReferenceDetailView(InstanceDetailView):

template_name = 'books/detail/references.html'
Expand Down Expand Up @@ -247,8 +216,6 @@ def get_context_data(self, **kwargs):
'facets': facets, # now includes ranges as facets.ranges
'total': self.queryset.count(),
'form': self.form,
# specify preview image for metadata
'page_meta_image': 'img/banner/[email protected]'
})
return context

Expand Down Expand Up @@ -381,8 +348,6 @@ def get_context_data(self, **kwargs):
'facets': facets,
'total': self.queryset.count(),
'form': self.form,
# specify preview image for metadata
'page_meta_image': 'img/banner/[email protected]'
})
return context

Expand Down Expand Up @@ -712,7 +677,14 @@ def get_proxy_url(self, *args, **kwargs):
'''
Return a proxy url for client browsers to access IIIF images from.
'''

instance = get_object_or_404(Instance, slug=self.kwargs['slug'])

# if instance has no digital edition associated, there are
# no images to be found
if not instance.digital_edition:
raise Http404

canvas_id = self.kwargs.get('short_id', None)
if canvas_id and canvas_id != 'default':
canvas = instance.images() \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
{% block page-subtitle %}{{ page.meta_title }} ‖ {% endblock %}
{% block nav-title %} {{ page.title }} {% endblock %}

{% block preview_meta %}
{# override preview image #}
{% with page_meta_image='img/banner/[email protected]' twitter_card='summary_large_image' %}
{{ block.super }}
{% endwith %}
{% endblock %}

{% block header_class %}mdl-layout__header--transparent{% endblock %}

{% block page-context-id %}interventions-list{% endblock %}
Expand Down
2 changes: 0 additions & 2 deletions derrida/interventions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,5 @@ def get_context_data(self, **kwargs):
'facets': facets,
'total': self.queryset.count(),
'form': self.form,
# specify preview image for metadata
'page_meta_image': 'img/banner/[email protected]'
})
return context
Loading

0 comments on commit 190d175

Please sign in to comment.