-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
143 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from django.core.serializers import serialize | ||
from .models import Manifest | ||
from apps.iiif.annotations.models import Annotation | ||
from datetime import datetime | ||
import json | ||
import zipfile | ||
import io | ||
|
||
class IiifManifestExport: | ||
@classmethod | ||
def get_zip(self, manifest, version): | ||
zip_subdir = manifest.label | ||
zip_filename = "iiif_export.zip" | ||
|
||
# Open BytesIO to grab in-memory ZIP contents | ||
byte_stream = io.BytesIO() | ||
|
||
# The zip compressor | ||
zf = zipfile.ZipFile(byte_stream, "w") | ||
|
||
# First write basic human-readable metadata | ||
title = manifest.label | ||
now = datetime.utcnow() | ||
readme = "Annotation export from Readux %(version)s\nExported at %(now)s UTC\nVolume: %(title)s\n" % locals() | ||
zf.writestr('README.txt', readme) | ||
|
||
# Next write the manifest | ||
zf.writestr('manifest.json', | ||
json.dumps( | ||
json.loads( | ||
serialize( | ||
'manifest', | ||
[manifest], | ||
version=version | ||
) | ||
), | ||
indent=4 | ||
) | ||
) | ||
|
||
# Then write the annotations | ||
for canvas in manifest.canvas_set.all(): | ||
if canvas.annotation_set.count() > 0: | ||
annotation_file = "annotation_list_" + canvas.pid + ".json" | ||
zf.writestr( | ||
annotation_file, | ||
json.dumps( | ||
json.loads( | ||
serialize( | ||
'annotation_list', | ||
[canvas], | ||
version=version | ||
) | ||
), | ||
indent=4 | ||
) | ||
) | ||
|
||
zf.close() # flush zipfile to byte stream | ||
|
||
return byte_stream.getvalue() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{% extends "base.html" %} | ||
{% load static i18n %} | ||
{% block extra_css %} | ||
<link href="{% static 'mirador/css/mirador-combined.css' %}" rel="stylesheet"> | ||
{% endblock extra_css %} | ||
|
||
{% block content %} | ||
|
||
<h1> NEW EXPORT PAGE</h1> | ||
<h1 class='uk-text-truncate'> | ||
{{volume.label}} | ||
</h1> | ||
{% endblock content %} | ||
{% block viewer %} | ||
<div class='uk-flex-center' uk-grid> | ||
<div class='uk-width-3-4'> | ||
<div class='uk-padding'> | ||
<b>Author:</b> {{ volume.author }} | ||
<br /> | ||
<b>Publication Date:</b> {{ volume.published_date }} | ||
<br />{% for col in volume.collections.all %} | ||
<b>Collection:</b> <a class="nav-link" href="{% url 'collection' col.pid %}">{{ col.label }}</a>{% endfor %} | ||
<br /> | ||
<b>Publisher:</b> {{ volume.published_city }} : {{ volume.publisher }} | ||
</div> | ||
<div class='uk-padding'> | ||
<h3>IIIF Export</h3> | ||
<p>Export volume and annotations as a IIIF bundle for preservation. (Note this is different than the IIIF Manifest URL for reuse.)</p> | ||
<form action="{% url 'ManifestExport' 'v2' volume.pid %}" class="button_to" method="POST"><div><input type="submit" value="Export IIIF Bundle" title="Export volume and annotations as a IIIF bundle for preservation."/>{% csrf_token %}</div></form> | ||
</div> | ||
|
||
<!-- start ocr el --> | ||
<div id='ocr' style='opacity: 0;'> | ||
|
||
</div> | ||
<!-- end ocr el --> | ||
</div> | ||
</div> | ||
{% endblock viewer %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters