Implements #19492: Add Save Button to Script Output Window

Add download button to custom script output header if job is completed
and there's output content
Add view condition of export query string and respond with a file
download including the job output content
This commit is contained in:
Omri Abu 2025-05-16 14:59:09 -04:00
parent cbe14b76c0
commit a483c85165
2 changed files with 20 additions and 1 deletions

View File

@ -1479,6 +1479,16 @@ class ScriptResultView(TableMixin, generic.ObjectView):
if job.completed: if job.completed:
table = self.get_table(job, request, bulk_actions=False) table = self.get_table(job, request, bulk_actions=False)
if job.completed and job.data and job.data.get('output'):
# If a direct export has been requested, return the job data content as a
# downloadable file.
if request.GET.get('export'):
content = job.data.get('output')
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) log_threshold = request.GET.get('log_threshold', LogLevelChoices.LOG_INFO)
if log_threshold not in LOG_LEVEL_RANK: if log_threshold not in LOG_LEVEL_RANK:
log_threshold = LogLevelChoices.LOG_INFO log_threshold = LogLevelChoices.LOG_INFO

View File

@ -53,7 +53,16 @@
{# Script output. Legacy reports will not have this. #} {# Script output. Legacy reports will not have this. #}
{% if 'output' in job.data %} {% if 'output' in job.data %}
<div class="card mb-3"> <div class="card mb-3">
<h2 class="card-header">{% trans "Output" %}</h2> <h2 class="card-header d-flex justify-content-between">
{% trans "Output" %}
{% if job.completed and job.data and job.data.output %}
<div>
<a href="?export=True" class="btn btn-primary lh-1" role="button">
<i class="mdi mdi-download" aria-hidden="true"></i> {% trans "Download" %}
</a>
</div>
{% endif %}
</h2>
{% if job.data.output %} {% if job.data.output %}
<pre class="card-body font-monospace">{{ job.data.output }}</pre> <pre class="card-body font-monospace">{{ job.data.output }}</pre>
{% else %} {% else %}