From 5ba7a6dc0f9c48a9bc1f108065c28b110a91f047 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Fri, 15 Nov 2024 14:50:19 +0100 Subject: [PATCH 1/2] hub/views: introduce the `_view_raw_file_by_ext()` helper No change in behavior intended with this commit. Related: https://github.com/openscanhub/openscanhub/issues/303 --- kobo/hub/views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kobo/hub/views.py b/kobo/hub/views.py index 3442e9a..8ea8ad8 100644 --- a/kobo/hub/views.py +++ b/kobo/hub/views.py @@ -184,6 +184,17 @@ def _rendered_log_response(request, task, log_name): return render(request, "task/log.html", context) +def _view_raw_file_by_ext(log_name): + """return True if we can view raw file with log_name based on its extension""" + exts = [".htm", ".html"] + + for ext in exts: + if log_name.endswith(ext): + return True + + return False + + def task_log(request, id, log_name): """ IMPORTANT: reverse to 'task/log-json' *must* exist @@ -197,7 +208,7 @@ def task_log(request, id, log_name): request_format = request.GET.get("format") - if request_format == "raw" or log_name.endswith(".html") or log_name.endswith(".htm"): + if request_format == "raw" or _view_raw_file_by_ext(log_name): return _streamed_log_response(task, log_name, offset, as_attachment=(request_format == 'raw')) return _rendered_log_response(request, task, log_name) From 5d5d6efd54af2cdc2ce718b5b661f469958769f4 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Mon, 18 Nov 2024 10:10:19 +0100 Subject: [PATCH 2/2] hub/views: introduce `VIEW_RAW_LOG_EXTENSIONS` setting ... in case the application needs to override the list of log files extensions to be viewed unrendered even when `?format=raw` is not used in the URL. Related: https://github.com/openscanhub/openscanhub/issues/303 Closes: https://github.com/release-engineering/kobo/pull/266 --- kobo/hub/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kobo/hub/views.py b/kobo/hub/views.py index 8ea8ad8..37d3803 100644 --- a/kobo/hub/views.py +++ b/kobo/hub/views.py @@ -186,7 +186,7 @@ def _rendered_log_response(request, task, log_name): def _view_raw_file_by_ext(log_name): """return True if we can view raw file with log_name based on its extension""" - exts = [".htm", ".html"] + exts = getattr(settings, "VIEW_RAW_LOG_EXTENSIONS", [".htm", ".html"]) for ext in exts: if log_name.endswith(ext):