From 3cb1f71b53ea91238339a6c7e1e76accf9065e98 Mon Sep 17 00:00:00 2001 From: Alexander Watzinger Date: Mon, 16 Oct 2023 18:04:53 +0200 Subject: [PATCH] IIIF clean up with Bernhard --- config/default.py | 2 +- openatlas/display/base_display.py | 2 +- openatlas/display/display.py | 4 ++-- openatlas/display/util.py | 6 +++--- openatlas/views/entity.py | 2 +- openatlas/views/entity_index.py | 6 +++--- tests/test_file.py | 28 +++++++++++++--------------- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/config/default.py b/config/default.py index d34d75a26..7f2aeb328 100644 --- a/config/default.py +++ b/config/default.py @@ -41,7 +41,7 @@ 'thumbnail': '200', 'table': '100'} IIIF = { - 'activate': False, + 'enabled': False, 'path': '', 'url': '', 'version': 2, diff --git a/openatlas/display/base_display.py b/openatlas/display/base_display.py index 21cd35d56..5d026696a 100644 --- a/openatlas/display/base_display.py +++ b/openatlas/display/base_display.py @@ -79,7 +79,7 @@ def get_type_data(self) -> dict[str, Any]: def add_file_tab_thumbnails(self) -> None: if 'file' in self.tabs and current_user.settings['table_show_icons']: - if app.config['IIIF']['activate'] \ + if app.config['IIIF']['enabled'] \ or g.settings['image_processing']: self.tabs['file'].table.header.insert(1, _('icon')) for row in self.tabs['file'].table.rows: diff --git a/openatlas/display/display.py b/openatlas/display/display.py index 1c3d38719..e5ce54fef 100644 --- a/openatlas/display/display.py +++ b/openatlas/display/display.py @@ -80,11 +80,11 @@ def add_button_others(self) -> None: if check_iiif_file_exist(self.entity.id) \ or not app.config['IIIF']['conversion']: self.buttons.append(button( - _('iiif'), + _('view in IIIF'), url_for('view_iiif', id_=self.entity.id))) else: self.buttons.append(button( - _('make_iiif_available'), + _('enable IIIF view'), url_for('make_iiif_available', id_=self.entity.id))) return self.buttons.append( diff --git a/openatlas/display/util.py b/openatlas/display/util.py index 71b235e4b..9a1a7b89c 100644 --- a/openatlas/display/util.py +++ b/openatlas/display/util.py @@ -233,7 +233,7 @@ def profile_image(entity: Entity) -> str: src = url_for('display_file', filename=path.name) url = src width = g.settings["profile_image_width"] - if app.config['IIIF']['activate'] and check_iiif_file_exist(entity.id): + if app.config['IIIF']['enabled'] and check_iiif_file_exist(entity.id): url = url_for('view_iiif', id_=entity.id) iiif_ext = '.tiff' if app.config['IIIF']['conversion'] \ else g.files[entity.id].suffix @@ -427,7 +427,7 @@ def system_warnings(_context: str, _unneeded_string: str) -> str: warnings.append( f"Database version {app.config['DATABASE_VERSION']} is needed but " f"current version is {g.settings['database_version']}") - if app.config['IIIF']['activate']: + if app.config['IIIF']['enabled']: if path := app.config['IIIF']['path']: check_write_access(path, warnings) for path in g.writable_paths: @@ -754,7 +754,7 @@ def get_entities_linked_to_type_recursive( def check_iiif_activation() -> bool: iiif = app.config['IIIF'] - return bool(iiif['activate'] and os.access(Path(iiif['path']), os.W_OK)) + return bool(iiif['enabled'] and os.access(Path(iiif['path']), os.W_OK)) def check_iiif_file_exist(id_: int) -> bool: diff --git a/openatlas/views/entity.py b/openatlas/views/entity.py index 6f2f8747f..778a96304 100644 --- a/openatlas/views/entity.py +++ b/openatlas/views/entity.py @@ -331,6 +331,6 @@ def delete_files(id_: int) -> None: path.unlink() for resized_path in app.config['RESIZED_IMAGES'].glob(f'**/{id_}.*'): resized_path.unlink() - if app.config['IIIF']['activate'] and check_iiif_file_exist(id_): + if app.config['IIIF']['enabled'] and check_iiif_file_exist(id_): if path := get_iiif_file_path(id_): path.unlink() diff --git a/openatlas/views/entity_index.py b/openatlas/views/entity_index.py index 4da44ba4d..d24df5b7b 100644 --- a/openatlas/views/entity_index.py +++ b/openatlas/views/entity_index.py @@ -42,7 +42,7 @@ def get_table(view: str) -> Table: if view == 'file': table.order = [[0, 'desc']] table.header = ['date'] + table.header - if (g.settings['image_processing'] or app.config['IIIF']['activate']) \ + if (g.settings['image_processing'] or app.config['IIIF']['enabled']) \ and current_user.settings['table_show_icons']: table.header.insert(1, _('icon')) for entity in Entity.get_by_class('file', types=True): @@ -54,7 +54,7 @@ def get_table(view: str) -> Table: entity.get_file_ext(), entity.description] if (g.settings['image_processing'] - or app.config['IIIF']['activate']) \ + or app.config['IIIF']['enabled']) \ and current_user.settings['table_show_icons']: data.insert(1, file_preview(entity.id)) table.rows.append(data) @@ -79,7 +79,7 @@ def get_table(view: str) -> Table: def file_preview(entity_id: int) -> str: size = app.config['IMAGE_SIZE']['table'] param = f"loading='lazy' alt='image' max-width='100px' max-height='100px'" - if app.config['IIIF']['activate'] and check_iiif_file_exist(entity_id): + if app.config['IIIF']['enabled'] and check_iiif_file_exist(entity_id): ext = '.tiff' if app.config['IIIF']['conversion'] \ else g.files[entity_id].suffix url = (f"{app.config['IIIF']['url']}{entity_id}{ext}" diff --git a/tests/test_file.py b/tests/test_file.py index ec2056fba..815d3cfcc 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import Any from flask import url_for @@ -17,10 +18,10 @@ def test_file(self) -> None: reference = insert('edition', 'Ancient Books') logo = Path(app.root_path) \ - / 'static' / 'images' / 'layout' / 'logo.png' + / 'static' / 'images' / 'layout' / 'logo.png' with open(logo, 'rb') as img_1, open(logo, 'rb') as img_2: - rv = self.app.post( + rv: Any = self.app.post( url_for('insert', class_='file', origin_id=place.id), data={'name': 'OpenAtlas logo', 'file': [img_1, img_2]}, follow_redirects=True) @@ -105,7 +106,7 @@ def test_file(self) -> None: assert b'Logo' in rv.data rv = self.app.get(url_for('view', id_=file_id)) - assert b'make_iiif_available' in rv.data + assert b'enable IIIF view' in rv.data rv = self.app.get( url_for('make_iiif_available', id_=file_id), @@ -113,26 +114,23 @@ def test_file(self) -> None: assert b'IIIF converted' in rv.data rv = self.app.get(url_for('view', id_=file_id)) - assert b'iiif' in rv.data + assert b'view in IIIF' in rv.data - rv = self.app.get(url_for( - 'api.iiif_manifest', - id_=file_id, - version=app.config['IIIF']['version'], - _external=True)) + rv = self.app.get( + url_for( + 'api.iiif_manifest', + id_=file_id, + version=app.config['IIIF']['version'])) rv = rv.get_json() assert bool(rv['label'] == 'Updated file') - rv = self.app.get( - url_for('api.iiif_sequence', id_=file_id)) + rv = self.app.get(url_for('api.iiif_sequence', id_=file_id)) rv = rv.get_json() assert bool(str(file_id) in rv['@id']) - rv = self.app.get( - url_for('api.iiif_image', id_=file_id)) + rv = self.app.get(url_for('api.iiif_image', id_=file_id)) rv = rv.get_json() assert bool(str(file_id) in rv['@id']) - rv = self.app.get( - url_for('api.iiif_canvas', id_=file_id)) + rv = self.app.get(url_for('api.iiif_canvas', id_=file_id)) rv = rv.get_json() assert bool(str(file_id) in rv['@id'])