Skip to content

Commit

Permalink
Merge pull request #266 from kdudka/raw-log
Browse files Browse the repository at this point in the history
introduce `VIEW_RAW_LOG_EXTENSIONS` setting
  • Loading branch information
rohanpm authored Nov 19, 2024
2 parents ea88252 + 5d5d6ef commit b809d8f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion kobo/hub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = getattr(settings, "VIEW_RAW_LOG_EXTENSIONS", [".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
Expand All @@ -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)
Expand Down

0 comments on commit b809d8f

Please sign in to comment.