Skip to content

Commit

Permalink
added button if file exist
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardKoschicek committed Sep 21, 2023
1 parent d2fae91 commit 7b7c6a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 11 additions & 5 deletions openatlas/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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)
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 @@ -75,10 +76,15 @@ def add_button_others(self) -> None:
self.buttons.append(button(
_('download'),
url_for('download_file', filename=path.name)))
if check_iiif():
self.buttons.append(button(
_('make_iiif_available'),
url_for('make_iiif_available', id_=self.entity.id)))
if check_iiif_activation():
if check_iiif_file_exist(self.entity.id):
self.buttons.append(button(
_('iiif'),
url_for('iiif', id_=self.entity.id)))
else:
self.buttons.append(button(
_('make_iiif_available'),
url_for('make_iiif_available', id_=self.entity.id)))
return
self.buttons.append(
'<span class="error">' + uc_first(_("missing file")) + '</span>')
Expand Down
7 changes: 6 additions & 1 deletion openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,13 @@ def get_entities_linked_to_type_recursive(
return data


def check_iiif() -> bool:
def check_iiif_activation() -> bool:
return True \
if (app.config['IIIF_ACTIVATE']
and os.access(Path(app.config['IIIF_DIR']), os.W_OK)) \
else False


def check_iiif_file_exist(id_: int) -> bool:
file_to_check = Path(app.config['IIIF_DIR']) / str(id_)
return file_to_check.is_file()
3 changes: 2 additions & 1 deletion openatlas/views/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def file_add(id_: int, view: str) -> Union[str, Response]:
@app.route('/file/iiif/<int:id_>', methods=['GET', 'POST'])
@required_group('contributor')
def make_iiif_available(id_: int):
call(f"convert {get_file_path(id_)} "
call_ = call(f"convert {get_file_path(id_)} "
f"-define tiff:tile-geometry=256x256 -compress jpeg "
f"'ptif:{app.config['IIIF_DIR']}/{id_}.tiff'", shell=True)
print(call_)
return redirect(url_for('view', id_=id_))

0 comments on commit 7b7c6a0

Please sign in to comment.