diff --git a/config/default.py b/config/default.py index de3b02d2d..5448c3589 100644 --- a/config/default.py +++ b/config/default.py @@ -38,9 +38,6 @@ # Image processing PROCESSED_IMAGE_DIR = Path(FILES_PATH) / 'processed_images' RESIZED_IMAGES = Path(PROCESSED_IMAGE_DIR) / 'resized' -IMAGE_SIZE = { - 'thumbnail': '200', - 'table': '100'} NONE_DISPLAY_EXT = ['.tiff', '.tif'] ALLOWED_IMAGE_EXT = DISPLAY_FILE_EXTENSIONS + NONE_DISPLAY_EXT PROCESSED_EXT = '.jpeg' diff --git a/install/3_data_web.sql b/install/3_data_web.sql index f87b9e54c..adcba3125 100644 --- a/install/3_data_web.sql +++ b/install/3_data_web.sql @@ -26,6 +26,8 @@ INSERT INTO web.settings (name, value) VALUES ('file_upload_allowed_extension', 'gif jpeg jpg pdf png txt zip'), ('geonames_username', 'openatlas'), ('image_processing', 'True'), + ('image_size_table', '100'), + ('image_size_thumbnail', '200'), ('log_level', '6'), ('logo_file_id', ''), ('mail', ''), diff --git a/install/upgrade/7.17.0.sql b/install/upgrade/7.17.0.sql index a7a6ed57b..34ce0936d 100644 --- a/install/upgrade/7.17.0.sql +++ b/install/upgrade/7.17.0.sql @@ -9,4 +9,8 @@ UPDATE web.settings SET value = '7.17.0' WHERE name = 'database_version'; -- #1442 API: CORS Settings in Backend UI INSERT INTO web.settings (name, value) VALUES ('api_core_allowance', '*'); +INSERT INTO web.settings (name, value) VALUES + ('image_size_table', '100'), + ('image_size_thumbnail', '200'); + END; diff --git a/install/upgrade/upgrade.md b/install/upgrade/upgrade.md index 2bd22facd..d4cc8964f 100644 --- a/install/upgrade/upgrade.md +++ b/install/upgrade/upgrade.md @@ -26,7 +26,9 @@ Following configuration parameters were moved from the .ini files to the database so that they can be adjusted via the backend. If you have changed the defaults you should adapt after the upgrade in the admin are. -* api_core_allowance (default = '*', former "CORS_ALLOWANCE" in default.ini) +* API: core allowance (default = '*', former CORS_ALLOWANCE in default.ini +* Image: size table (default 100), size thumbnail (default 200), + former IMAGE_SIZE in default.ini ### 7.15.0 to 7.16.0 7.16.0.sql is needed but will be taken care of by the database upgrade script. diff --git a/openatlas/api/endpoints/content.py b/openatlas/api/endpoints/content.py index 68d383f85..64012df78 100644 --- a/openatlas/api/endpoints/content.py +++ b/openatlas/api/endpoints/content.py @@ -21,7 +21,7 @@ def get() -> Union[tuple[Resource, int], Response]: 'intro': get_translation('intro_for_frontend', lang), 'contact': get_translation('contact_for_frontend', lang), 'siteName': get_translation('site_name_for_frontend', lang), - 'imageSizes': app.config['IMAGE_SIZE'], + 'imageSizes': g.settings['image_size'], 'legalNotice': get_translation('legal_notice_for_frontend', lang)} if parser['download']: download(content, content_template(), 'content') diff --git a/openatlas/api/endpoints/display_image.py b/openatlas/api/endpoints/display_image.py index 57dd85035..23ae27f98 100644 --- a/openatlas/api/endpoints/display_image.py +++ b/openatlas/api/endpoints/display_image.py @@ -1,9 +1,8 @@ from pathlib import Path as Pathlib_path -from flask import Response, send_file +from flask import Response, send_file, g from flask_restful import Resource -from openatlas import app from openatlas.api.resources.error import DisplayFileNotFoundError, \ NoLicenseError from openatlas.api.resources.parser import image @@ -21,7 +20,7 @@ def get(filename: str) -> Response: parser = image.parse_args() filepath = get_file_path( entity, - app.config['IMAGE_SIZE'][parser['image_size']] + g.settings['image_size'][parser['image_size']] if parser['image_size'] else None) if not filepath: raise DisplayFileNotFoundError diff --git a/openatlas/api/resources/parser.py b/openatlas/api/resources/parser.py index 16ea7d41e..3c507b1b6 100644 --- a/openatlas/api/resources/parser.py +++ b/openatlas/api/resources/parser.py @@ -1,3 +1,4 @@ +from flask import g from flask_restful import reqparse from openatlas import app @@ -154,4 +155,4 @@ type=str, help="{error_msg}", case_sensitive=False, - choices=list(size for size in app.config['IMAGE_SIZE'])) + choices=list(size for size in g.settings['image_size'])) diff --git a/openatlas/display/image_processing.py b/openatlas/display/image_processing.py index 8cea34e5b..89b64ad8d 100644 --- a/openatlas/display/image_processing.py +++ b/openatlas/display/image_processing.py @@ -13,7 +13,7 @@ def resize_image(filename: str) -> None: def loop_resize_image(name: str, file_format: str) -> None: - for size in app.config['IMAGE_SIZE'].values(): + for size in g.settings['image_size'].values(): safe_resize_image(name, file_format, size) @@ -64,7 +64,7 @@ def check_processed_image(filename: str) -> bool: def loop_through_processed_folders(name: str, file_format: str) -> bool: ext = app.config['PROCESSED_EXT'] \ if file_format in app.config['NONE_DISPLAY_EXT'] else file_format - for size in app.config['IMAGE_SIZE'].values(): + for size in g.settings['image_size'].values(): path = Path(app.config['RESIZED_IMAGES']) / size / f"{name}{ext}" if not path.is_file() \ and not safe_resize_image(name, file_format, size): @@ -87,7 +87,7 @@ def create_folder(folder: Path) -> bool: # pragma: no cover def delete_orphaned_resized_images() -> None: - for size in app.config['IMAGE_SIZE'].values(): + for size in g.settings['image_size'].values(): path = Path(app.config['RESIZED_IMAGES']) / size for file in path.glob('**/*'): file_name = file.name.rsplit('.', 1)[0].lower() diff --git a/openatlas/display/util.py b/openatlas/display/util.py index 7ab463d7c..c192e58ff 100644 --- a/openatlas/display/util.py +++ b/openatlas/display/util.py @@ -236,7 +236,7 @@ def profile_image(entity: Entity) -> str: if not path: return '' # pragma: no cover resized = None - size = app.config['IMAGE_SIZE']['thumbnail'] + size = g.settings['image_size']['thumbnail'] if g.settings['image_processing'] and check_processed_image(path.name): if path_ := get_file_path(entity.image_id, size): resized = url_for('display_file', filename=path_.name, size=size) @@ -245,7 +245,7 @@ def profile_image(entity: Entity) -> str: style = f'max-width:{g.settings["profile_image_width"]}px;' ext = app.config["DISPLAY_FILE_EXTENSIONS"] if resized: - style = f'max-width:{app.config["IMAGE_SIZE"]["thumbnail"]}px;' + style = f'max-width:{g.settings["image_size"]["thumbnail"]}px;' ext = app.config["ALLOWED_IMAGE_EXT"] if entity.class_.view == 'file': html = \ diff --git a/openatlas/views/entity_index.py b/openatlas/views/entity_index.py index 842df7c9d..53908868d 100644 --- a/openatlas/views/entity_index.py +++ b/openatlas/views/entity_index.py @@ -78,16 +78,16 @@ def get_table(view: str) -> Table: def file_preview(entity_id: int) -> str: - size = app.config['IMAGE_SIZE']['table'] + size = g.settings['image_size']['table'] parameter = f"loading='lazy' alt='image' width='{size}'" if icon_path := get_file_path( entity_id, - app.config['IMAGE_SIZE']['table']): + g.settings['image_size']['table']): url = url_for('display_file', filename=icon_path.name, size=size) return f"" path = get_file_path(entity_id) if path and check_processed_image(path.name): - if icon := get_file_path(entity_id, app.config['IMAGE_SIZE']['table']): + if icon := get_file_path(entity_id, g.settings['image_size']['table']): url = url_for('display_file', filename=icon.name, size=size) return f"" return ''