mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -06:00
Add condition to ScriptResultView.get function to generate a download
file of job output if job is completed
This commit is contained in:
parent
334b45f55a
commit
5f47ba4fb2
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user