Add condition to ScriptResultView.get function to generate a download

file of job output if job is completed
This commit is contained in:
Omri Abu 2025-06-18 10:07:44 -04:00
parent 334b45f55a
commit 5f47ba4fb2

View File

@ -1479,6 +1479,16 @@ class ScriptResultView(TableMixin, generic.ObjectView):
if job.completed:
table = self.get_table(job, request, bulk_actions=False)
if job.completed:
# If a direct export output has been requested, return the job data content as a
# downloadable file.
if request.GET.get('export') == 'output':
content = (job.data.get("output") or "").encode()
response = HttpResponse(content, content_type='text')
filename = f"{job.object.name or 'script-output'}_{job.completed.strftime('%Y-%m-%d-%H-%M-%S')}.txt"
response['Content-Disposition'] = f'attachment; filename="{filename}"'
return response
log_threshold = request.GET.get('log_threshold', LogLevelChoices.LOG_INFO)
if log_threshold not in LOG_LEVEL_RANK:
log_threshold = LogLevelChoices.LOG_INFO