Remove log output feature

Remove job.data check and output empty string for completed job with no
output
This commit is contained in:
Omri Abu 2025-06-09 17:35:00 -04:00
parent b0f61c6288
commit c3828aa142
2 changed files with 4 additions and 27 deletions

View File

@ -1482,34 +1482,16 @@ class ScriptResultView(TableMixin, generic.ObjectView):
if job.completed:
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
# downloadable file.
if request.GET.get('export') == 'output' and job.data.get('output'):
content = job.data['output'].encode()
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
# 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)
if log_threshold not in LOG_LEVEL_RANK:
log_threshold = LogLevelChoices.LOG_INFO

View File

@ -42,11 +42,6 @@
<div class="table-responsive" id="object_list">
<h2 class="card-header d-flex justify-content-between">
{% 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>
<div class="htmx-container table-responsive"
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">
<h2 class="card-header d-flex justify-content-between">
{% trans "Output" %}
{% if job.data.output %}
{% if job.completed %}
<div>
<a href="?export=output" class="btn btn-primary lh-1" role="button">
<i class="mdi mdi-download" aria-hidden="true"></i> {% trans "Download" %}