Skip to content

Commit

Permalink
Only show export if a user has annotated a volume.
Browse files Browse the repository at this point in the history
This adds the logged-in user's ID to the annotation table in `owner_id`,
recording the ownership of each annotation.  It then uses this to
determine whether or not to display the "Export" button on the volume
home page.
  • Loading branch information
benwbrum committed May 10, 2019
1 parent 93a02da commit 2fb0d39
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/iiif/canvases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def post(self, request, *args, **kwargs):
payload = json.loads(request.body.decode('utf-8'))
oa_annotation = json.loads(payload['oa_annotation'])
canvas = Canvas.objects.get(pid=oa_annotation['on'][0]['full'].split('/')[-1])
user_id = request.user.id
annotation = Annotation()
annotation.canvas = canvas
annotation.oa_annotation = oa_annotation
annotation.owner_id = user_id
annotation.save()
return JsonResponse(oa_annotation, safe=False)

Expand Down
5 changes: 4 additions & 1 deletion apps/readux/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ..iiif.kollections.models import Collection
from ..iiif.canvases.models import Canvas
from ..iiif.manifests.models import Manifest
from ..iiif.annotations.models import Annotation


class CollectionsList(ListView):
Expand Down Expand Up @@ -61,7 +62,9 @@ class PageDetail(TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['page'] = Canvas.objects.filter(pid=kwargs['page']).first()
context['volume'] = Manifest.objects.filter(pid=kwargs['volume']).first()
manifest = Manifest.objects.filter(pid=kwargs['volume']).first()
context['volume'] = manifest
context['user_annotation_count'] = Annotation.objects.filter(owner_id=self.request.user.id).filter(canvas__manifest__id=manifest.id).count()
return context

class ExportOptions(TemplateView):
Expand Down
5 changes: 3 additions & 2 deletions apps/templates/export.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

{% block content %}

<h1> NEW EXPORT PAGE</h1>
<h1>{{request.user.id}}</h1>
<h1 class='uk-text-truncate'>
{{volume.label}}
{{volume.label}}

</h1>
{% endblock content %}
{% block viewer %}
Expand Down
2 changes: 2 additions & 0 deletions apps/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ <h1 class='uk-text-truncate'>
<br />
<b>Stable page URL:</b> <span class="link" id="mySpan"></span>
<br />
{% if user_annotation_count > 0 %}
<form action="{% url 'export' col.pid volume.pid %}" class="button_to" method="GET"><div><input type="submit" value="Export" title="Export in a variety of formats"/>{% csrf_token %}</div></form>
{% endif %}
<!--
<p id="test"></p>
<a class="facebook" href='http://www.facebook.com/sharer.php?s=100&p[url]=http://{{ request.META.HTTP_HOST }}{{ request.path }}&p[images][0]{{ page.IIIF_IMAGE_SERVER_BASE }}{{ page.pid }}/full/600,/0/default.jpg' target="_blank">
Expand Down

0 comments on commit 2fb0d39

Please sign in to comment.