Skip to content

Commit

Permalink
Refine IIIF buttons layout with Bernhard
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Nov 3, 2023
1 parent 8e0cf46 commit 0fe27a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
14 changes: 1 addition & 13 deletions openatlas/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
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, check_iiif_file_exist)
get_file_path, is_authorized, link, remove_link, uc_first)
from openatlas.models.entity import Entity
from openatlas.views.tools import carbon_result, sex_result

Expand Down Expand Up @@ -74,17 +73,6 @@ def add_button_others(self) -> None:
self.buttons.append(button(
_('download'),
url_for('download_file', filename=path.name)))
if check_iiif_activation() \
and self.entity.get_file_ext() in g.display_file_ext:
if check_iiif_file_exist(self.entity.id) \
or not g.settings['iiif_conversion']:
self.buttons.append(button(
_('view in IIIF'),
url_for('view_iiif', id_=self.entity.id)))
else:
self.buttons.append(button(
_('enable IIIF view'),
url_for('make_iiif_available', id_=self.entity.id)))
return
self.buttons.append(
'<span class="error">' + uc_first(_("missing file")) + '</span>')
Expand Down
32 changes: 25 additions & 7 deletions openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,35 +230,52 @@ def profile_image(entity: Entity) -> str:
if not (path := get_file_path(entity.image_id)):
return '' # pragma: no cover

file_id = entity.image_id
src = url_for('display_file', filename=path.name)
url = src
width = g.settings["profile_image_width"]
if g.settings['iiif'] and check_iiif_file_exist(entity.id):
url = url_for('view_iiif', id_=entity.id)

if g.settings['iiif'] and check_iiif_file_exist(file_id):
iiif_ext = '.tiff' if g.settings['iiif_conversion'] \
else g.files[entity.id].suffix
else g.files[file_id].suffix
src = \
f"{g.settings['iiif_url']}{entity.id}{iiif_ext}" \
f"{g.settings['iiif_url']}{file_id}{iiif_ext}" \
f"/full/!{width},{width}/0/default.jpg"
elif g.settings['image_processing'] and check_processed_image(path.name):
if path_ := get_file_path(
entity.image_id,
file_id,
app.config['IMAGE_SIZE']['thumbnail']):
src = url_for(
'display_file',
size=app.config['IMAGE_SIZE']['thumbnail'],
filename=path_.name)

external = False
if entity.class_.view == 'file':
external = True
if path.suffix.lower() not in g.display_file_ext:
return '<p class="uc-first">' + _('no preview available') + '</p>'
else:
url = url_for('view', id_=entity.image_id)

html = link(
f'<img style="max-width:{width}px" alt="{entity.name}" src="{src}">',
url,
external=external)

if check_iiif_activation() \
and g.files[file_id].suffix in g.display_file_ext:
if check_iiif_file_exist(file_id) \
or not g.settings['iiif_conversion']:
html += '<br>' + link(
_('view in IIIF'),
url_for('view_iiif', id_=file_id),
external=True)
else:
html += button_bar([
button(
_('enable IIIF view'),
url_for('make_iiif_available', id_=file_id))])
return html


Expand Down Expand Up @@ -750,8 +767,9 @@ def get_entities_linked_to_type_recursive(


def check_iiif_activation() -> bool:
return bool(g.settings['iiif'] and
os.access(Path(g.settings['iiif_path']), os.W_OK))
return bool(
g.settings['iiif'] and
os.access(Path(g.settings['iiif_path']), os.W_OK))


def check_iiif_file_exist(id_: int) -> bool:
Expand Down

0 comments on commit 0fe27a7

Please sign in to comment.