diff --git a/openatlas/display/display.py b/openatlas/display/display.py index 812c13441..9ae37da28 100644 --- a/openatlas/display/display.py +++ b/openatlas/display/display.py @@ -5,6 +5,7 @@ from flask import g, url_for from flask_babel import lazy_gettext as _ +from openatlas import app from openatlas.display.base_display import ( ActorDisplay, BaseDisplay, EventsDisplay, PlaceBaseDisplay, ReferenceBaseDisplay, TypeBaseDisplay) @@ -12,7 +13,8 @@ from openatlas.display.table import Table from openatlas.display.util import ( button, description, edit_link, format_entity_date, get_base_table_data, - get_file_path, is_authorized, link, remove_link, uc_first, check_iiif_activation, + get_file_path, is_authorized, link, remove_link, uc_first, + check_iiif_activation, check_iiif_file_exist) from openatlas.models.entity import Entity from openatlas.views.tools import carbon_result, sex_result @@ -80,7 +82,9 @@ def add_button_others(self) -> None: if check_iiif_file_exist(self.entity.id): self.buttons.append(button( _('iiif'), - url_for('view_iiif', id_=self.entity.id))) + url_for('view_iiif', + prefix=app.config['IIIF_PREFIX'], + id_=self.entity.id))) else: self.buttons.append(button( _('make_iiif_available'), @@ -99,8 +103,8 @@ def add_tabs(self) -> None: super().add_tabs() entity = self.entity for name in [ - 'source', 'event', 'actor', 'place', 'feature', - 'stratigraphic_unit', 'artifact', 'reference', 'type']: + 'source', 'event', 'actor', 'place', 'feature', + 'stratigraphic_unit', 'artifact', 'reference', 'type']: self.tabs[name] = Tab(name, entity=entity) entity.image_id = entity.id if get_file_path(entity.id) else None for link_ in entity.get_links('P67'): @@ -296,8 +300,8 @@ def add_tabs(self) -> None: super().add_tabs() entity = self.entity for name in [ - 'actor', 'artifact', 'feature', 'event', 'place', - 'stratigraphic_unit', 'text', 'reference', 'file']: + 'actor', 'artifact', 'feature', 'event', 'place', + 'stratigraphic_unit', 'text', 'reference', 'file']: self.tabs[name] = Tab(name, entity=entity) for text in entity.get_linked_entities('P73', types=True): self.tabs['text'].table.rows.append([ diff --git a/openatlas/display/util.py b/openatlas/display/util.py index e197c00b1..2b4943a22 100644 --- a/openatlas/display/util.py +++ b/openatlas/display/util.py @@ -765,5 +765,6 @@ def check_iiif_activation() -> bool: def check_iiif_file_exist(id_: int) -> bool: - file_to_check = Path(app.config['IIIF_DIR']) / str(id_) + file_to_check = (Path(app.config['IIIF_DIR']) + / app.config['IIIF_PREFIX'] / str(id_)) return file_to_check.is_file() diff --git a/openatlas/views/file.py b/openatlas/views/file.py index 15d230d2a..37cda21fd 100644 --- a/openatlas/views/file.py +++ b/openatlas/views/file.py @@ -1,7 +1,10 @@ +import json import subprocess from pathlib import Path -from typing import Any, Union +from typing import Any, Union, Optional +from iiif_prezi import factory +from iiif_prezi.factory import ManifestFactory from flask import g, render_template, request, send_from_directory, url_for from flask_babel import lazy_gettext as _ from werkzeug.utils import redirect @@ -87,6 +90,26 @@ def convert_image_to_iiif(id_): @app.route('/iiif/', methods=['GET']) +@app.route('/iiif//', methods=['GET']) @required_group('contributor') -def view_iiif(id_: int): - return redirect(url_for('view', id_=id_)) +def view_iiif(id_: int, prefix: Optional[str] = None): + fac = ManifestFactory() + # Where the resources live on the web + fac.set_base_prezi_uri(request.url) + # Where the resources live on disk + image_path = Path(app.config['IIIF_DIR']) / app.config['IIIF_PREFIX'] + fac.set_base_prezi_dir(image_path) + + # Default Image API information + fac.set_base_image_uri(request.url) + fac.set_iiif_image_info(2.0, 2) # Version, ComplianceLevel + + # 'warn' will print warnings, default level + # 'error' will turn off warnings + # 'error_on_warning' will make warnings into errors + fac.set_debug("warn") + entity = Entity.get_by_id(id_) + manifest = fac.manifest(label=entity.name) + manifest.description = entity.description + mfst = manifest.toJSON(top=True) + return json.dumps(mfst)