Skip to content

Commit

Permalink
Merge branch 'feature/iiif' into feature/path_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Oct 12, 2023
2 parents 3654c4d + 08bff1c commit a58c97e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
6 changes: 3 additions & 3 deletions openatlas/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def add_routes_v03(api: Api) -> None:
endpoint='iiif_manifest')
api.add_resource(
IIIFImageV2,
'/iiif_image/<int:version>/<int:id_>.json',
'/iiif_image/<int:id_>.json',
endpoint='iiif_image')
api.add_resource(
IIIFCanvasV2,
'/iiif_canvas/<int:version>/<int:id_>.json',
'/iiif_canvas/<int:id_>.json',
endpoint='iiif_canvas')
api.add_resource(
IIIFSequenceV2,
'/iiif_sequence/<int:version>/<int:id_>.json',
'/iiif_sequence/<int:id_>.json',
endpoint='iiif_sequence')
4 changes: 2 additions & 2 deletions openatlas/display/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def image_resizing(name: str, format_: str, size: str) -> bool:
filename = Path(app.config['UPLOAD_PATH']) / f"{name}{format_}[0]"
with Image(filename=filename) as src:
if format_ in app.config['PROCESSABLE_EXT']:
format_ = app.config['PROCESSED_EXT']
format_ = app.config['PROCESSED_EXT'] # pragma: no cover
with src.convert(format_.replace('.', '')) as img:
img.transform(resize=f"{size}x{size}>")
img.compression_quality = 75
Expand Down Expand Up @@ -62,7 +62,7 @@ def check_processed_image(filename: str) -> bool:
def loop_through_processed_folders(name: str, file_format: str) -> bool:
ext = file_format
if file_format in app.config['PROCESSABLE_EXT']:
ext = app.config['PROCESSED_EXT']
ext = app.config['PROCESSED_EXT'] # pragma: no cover
for size in app.config['IMAGE_SIZE'].values():
path = Path(app.config['RESIZED_IMAGES']) / size / f"{name}{ext}"
if not path.is_file() \
Expand Down
5 changes: 2 additions & 3 deletions openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,7 @@ def check_iiif_activation() -> bool:
def check_iiif_file_exist(id_: int) -> bool:
if app.config['IIIF']['conversion']:
return get_iiif_file_path(id_).is_file()
else:
return bool(get_file_path(id_))
return bool(get_file_path(id_))


def get_iiif_file_path(id_: int) -> Path:
Expand All @@ -783,5 +782,5 @@ def convert_image_to_iiif(id_: int) -> None:
process = subprocess.Popen(command, shell=True)
process.wait()
flash(_('IIIF converted'), 'info')
except Exception as e:
except Exception as e: # pragma: no cover
flash(f"{_('failed to convert image')}: {e}", 'error')
2 changes: 1 addition & 1 deletion openatlas/views/entity_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def file_preview(entity_id: int) -> str:
url = (f"{app.config['IIIF']['url']}{entity_id}{ext}"
f"/full/!100,100/0/default.jpg")
return f"<img src='{url}' {param}>" \
if ext in app.config["IIIF_IMAGE_EXT"] else ''
if ext in g.display_file_ext else ''
if icon_path := get_file_path(
entity_id,
app.config['IMAGE_SIZE']['table']):
Expand Down
11 changes: 6 additions & 5 deletions openatlas/views/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ def make_iiif_available(id_: int) -> Response:
def view_iiif(id_: int) -> str:
return render_template(
'iiif.html',
manifest_url=url_for(
'api.iiif_manifest',
id_=id_,
version=app.config['IIIF']['version'],
_external=True))
manifest_url=
url_for(
'api.iiif_manifest',
id_=id_,
version=app.config['IIIF']['version'],
_external=True))
38 changes: 37 additions & 1 deletion tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,53 @@ def test_file(self) -> None:
follow_redirects=True)
assert b'Updated file' in rv.data

rv = self.app.get(url_for('view', id_=file_id))
assert b'Logo' in rv.data

rv = self.app.get(url_for('view', id_=file_id))
assert b'make_iiif_available' 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'Logo' in rv.data
assert b'iiif' in rv.data

rv = self.app.get(url_for(
'api.iiif_manifest',
id_=file_id,
version=app.config['IIIF']['version'],
_external=True))
assert b'/iiif/2/145.tiff' in rv.data

rv = self.app.get(
url_for('api.iiif_sequence', id_=file_id))
assert b'/iiif/2/145.tiff' in rv.data
rv = self.app.get(
url_for('api.iiif_image', id_=file_id))
assert b'/iiif/2/145.tiff' in rv.data
rv = self.app.get(
url_for('api.iiif_canvas', id_=file_id))
assert b'/iiif/2/145.tiff' in rv.data

rv = self.app.get(url_for('view_iiif', id_=file_id))
assert b'Mirador' in rv.data

rv = self.app.get(url_for('view', id_=place.id))
assert b'/full/!100,100/0/default.jpg' in rv.data

app.config['IIIF']['conversion'] = False
rv = self.app.get(url_for('view', id_=place.id))
assert b'/full/!100,100/0/default.jpg' in rv.data

app.config['IIIF']['activate'] = False
rv = self.app.get(url_for('view', id_=place.id))
assert b'Logo' in rv.data

app.config['IIIF']['activate'] = True
app.config['IIIF']['conversion'] = True
for file in files:
rv = self.app.get(
url_for('delete', id_=file.id),
Expand Down

0 comments on commit a58c97e

Please sign in to comment.