Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce VIEW_RAW_LOG_EXTENSIONS setting #266

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading