Skip to content

Commit

Permalink
Admin settings (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Sep 20, 2023
1 parent 77636a1 commit ff76074
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 17 deletions.
3 changes: 0 additions & 3 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions install/3_data_web.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''),
Expand Down
4 changes: 4 additions & 0 deletions install/upgrade/7.17.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 3 additions & 1 deletion install/upgrade/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion openatlas/api/endpoints/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 2 additions & 3 deletions openatlas/api/endpoints/display_image.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion openatlas/api/resources/parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask import g
from flask_restful import reqparse

from openatlas import app
Expand Down Expand Up @@ -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']))
6 changes: 3 additions & 3 deletions openatlas/display/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions openatlas/display/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = \
Expand Down
6 changes: 3 additions & 3 deletions openatlas/views/entity_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<img src='{url}' {parameter}>"
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"<img src='{url}' {parameter}>"
return ''

0 comments on commit ff76074

Please sign in to comment.