Skip to content

Commit

Permalink
Merge pull request #46 from bis-med-it/uploaded_yaml_fix
Browse files Browse the repository at this point in the history
Uploaded yaml fix
  • Loading branch information
pietropatelli committed Nov 14, 2023
2 parents 0a413d4 + b08646e commit 08bd4a7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
12 changes: 6 additions & 6 deletions images/pylint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 42 additions & 11 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""application"""
import asyncio
import base64
import glob
import io
import os
import platform
from itertools import islice
Expand All @@ -21,15 +23,10 @@
get_components_async,
get_translation,
get_url_cl,
translate_df,
retreive_codes_from_data,
translate_df,
)
from src.utils import (
snake_case,
cleanhtml,
error_box,
validate_yamlfile,
)
from src.utils import cleanhtml, error_box, snake_case, validate_yamlfile

external_stylesheets = [
dbc.themes.COSMO,
Expand Down Expand Up @@ -210,7 +207,7 @@
],
)
def get_language(*args):
""" Get the language code as returned by the callback
"""Get the language code as returned by the callback
:param *args: the language code clicked in the dropdown
:returns: string with the language code requested which is cached
Expand Down Expand Up @@ -299,6 +296,42 @@ def load_yamlfile(filename: str, folder: str = None) -> dict:
raise PreventUpdate from e


@callback(
Output("settings", "data"),
Output("is_loaded", "data"),
Output("yaml_file_invalid", "children"),
Input("upload-data", "contents"),
State("upload-data", "filename"),
)
def load_content_uploaded(uploaded_file, filename):
"""update_output returns a dictionary with the settings from the uploaded
YAML file and a boolean on whether the settings are loaded
:param uploaded_file: the path of the YAML file
:returns: a dictionary with the settings and a boolean when the loading is completed
"""

if uploaded_file is None:
raise PreventUpdate
elif ".yaml" not in filename:
raise PreventUpdate

try:
content_type, content_string = uploaded_file.split(",")
decoded = base64.b64decode(content_string)
data = yaml.safe_load(io.BytesIO(decoded))
validation = validate_yamlfile(data)
if validation:
out = None, None, error_box(f"Invalid YAML file. Error:{validation.code}")
else:
is_loaded = True
out = data, is_loaded, ""
return out

except Exception as e:
print(e)
raise PreventUpdate from e


@callback(
Output("yaml_file", "data"), [Input("url", "href")], prevent_initial_call=True
)
Expand Down Expand Up @@ -1462,9 +1495,7 @@ async def download_single_chart(data_chart, row: int, pos: int):

# Fallback to descendants but less performant
except Exception as e:
print(
f"Invalid dsdLink for {chart_id}. Falling back to default. Error:{e}"
)
print(f"Invalid dsdLink for {chart_id}. Falling back to default. Error:{e}")
if data_chart["metadataLink"]:
# Metadata
try:
Expand Down

0 comments on commit 08bd4a7

Please sign in to comment.