mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 13:06:30 -06:00
Remove log output feature
Remove job.data check and output empty string for completed job with no output
This commit is contained in:
parent
b0f61c6288
commit
c3828aa142
@ -1482,34 +1482,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:
|
if job.completed:
|
||||||
# If a direct export output has been requested, return the job data content as a
|
# If a direct export output has been requested, return the job data content as a
|
||||||
# downloadable file.
|
# downloadable file.
|
||||||
if request.GET.get('export') == 'output' and job.data.get('output'):
|
if request.GET.get('export') == 'output':
|
||||||
content = job.data['output'].encode()
|
content = (job.data.get("output") or "").encode()
|
||||||
response = HttpResponse(content, content_type='text')
|
response = HttpResponse(content, content_type='text')
|
||||||
filename = f"{job.object.name or 'script-output'}_{job.completed.strftime('%Y-%m-%d-%H-%M-%S')}.txt"
|
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}"'
|
response['Content-Disposition'] = f'attachment; filename="{filename}"'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# If a direct export log has been requested, return the job log content as a
|
|
||||||
# downloadable CSV file.
|
|
||||||
if request.GET.get('export') == 'log' and table:
|
|
||||||
# Filter generator for visible columns
|
|
||||||
def column_filter(data):
|
|
||||||
for item in data:
|
|
||||||
yield dict((k, v) for k, v, in item.items() if k in table.columns.names())
|
|
||||||
# Write a CSV to a string buffer for content
|
|
||||||
buf = StringIO()
|
|
||||||
writer = csv.DictWriter(buf, fieldnames=table.columns.names())
|
|
||||||
writer.writeheader()
|
|
||||||
writer.writerows(column_filter(table.data))
|
|
||||||
buf.seek(0)
|
|
||||||
response = HttpResponse(buf.read().encode(), content_type='text/csv')
|
|
||||||
filename = f"{job.object.name or 'script-log'}_{job.completed.strftime('%Y-%m-%d-%H-%M-%S')}.csv"
|
|
||||||
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
|
||||||
|
@ -42,11 +42,6 @@
|
|||||||
<div class="table-responsive" id="object_list">
|
<div class="table-responsive" id="object_list">
|
||||||
<h2 class="card-header d-flex justify-content-between">
|
<h2 class="card-header d-flex justify-content-between">
|
||||||
{% trans "Log" %}
|
{% trans "Log" %}
|
||||||
<div>
|
|
||||||
<a href="?export=log" class="btn btn-primary lh-1" role="button">
|
|
||||||
<i class="mdi mdi-download" aria-hidden="true"></i> {% trans "Download" %}
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</h2>
|
</h2>
|
||||||
<div class="htmx-container table-responsive"
|
<div class="htmx-container table-responsive"
|
||||||
hx-get="{% url 'extras:script_result' job_pk=job.pk %}?embedded=True&log=True&log_threshold={{log_threshold}}"
|
hx-get="{% url 'extras:script_result' job_pk=job.pk %}?embedded=True&log=True&log_threshold={{log_threshold}}"
|
||||||
@ -62,7 +57,7 @@
|
|||||||
<div class="card mb-3">
|
<div class="card mb-3">
|
||||||
<h2 class="card-header d-flex justify-content-between">
|
<h2 class="card-header d-flex justify-content-between">
|
||||||
{% trans "Output" %}
|
{% trans "Output" %}
|
||||||
{% if job.data.output %}
|
{% if job.completed %}
|
||||||
<div>
|
<div>
|
||||||
<a href="?export=output" class="btn btn-primary lh-1" role="button">
|
<a href="?export=output" class="btn btn-primary lh-1" role="button">
|
||||||
<i class="mdi mdi-download" aria-hidden="true"></i> {% trans "Download" %}
|
<i class="mdi mdi-download" aria-hidden="true"></i> {% trans "Download" %}
|
||||||
|
Loading…
Reference in New Issue
Block a user