Skip to content

Commit

Permalink
trying prezi
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Sep 22, 2023
1 parent c8a5b7c commit 955e808
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
16 changes: 10 additions & 6 deletions openatlas/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
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)
from openatlas.display.tab import Tab
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
Expand Down Expand Up @@ -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'),
Expand All @@ -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'):
Expand Down Expand Up @@ -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([
Expand Down
3 changes: 2 additions & 1 deletion openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
29 changes: 26 additions & 3 deletions openatlas/views/file.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -87,6 +90,26 @@ def convert_image_to_iiif(id_):


@app.route('/iiif/<int:id_>', methods=['GET'])
@app.route('/iiif/<prefix>/<int:id_>', 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)

0 comments on commit 955e808

Please sign in to comment.