mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
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:
parent
cbe14b76c0
commit
a483c85165
@ -1479,6 +1479,16 @@ class ScriptResultView(TableMixin, generic.ObjectView):
|
||||
if job.completed:
|
||||
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)
|
||||
if log_threshold not in LOG_LEVEL_RANK:
|
||||
log_threshold = LogLevelChoices.LOG_INFO
|
||||
|
@ -53,7 +53,16 @@
|
||||
{# Script output. Legacy reports will not have this. #}
|
||||
{% if 'output' in job.data %}
|
||||
<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 %}
|
||||
<pre class="card-body font-monospace">{{ job.data.output }}</pre>
|
||||
{% else %}
|
||||
|
Loading…
Reference in New Issue
Block a user