Skip to content

Commit

Permalink
IIIF clean up with Bernhard
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Oct 16, 2023
1 parent 8959a92 commit 3cb1f71
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'thumbnail': '200',
'table': '100'}
IIIF = {
'activate': False,
'enabled': False,
'path': '',
'url': '',
'version': 2,
Expand Down
2 changes: 1 addition & 1 deletion openatlas/display/base_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions openatlas/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion openatlas/views/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions openatlas/views/entity_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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}"
Expand Down
28 changes: 13 additions & 15 deletions tests/test_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Any

from flask import url_for

Expand All @@ -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)
Expand Down Expand Up @@ -105,34 +106,31 @@ 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),
follow_redirects=True)
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'])

Expand Down

0 comments on commit 3cb1f71

Please sign in to comment.