Show results in report/script lists

This commit is contained in:
jeremystretch 2023-03-24 12:32:52 -04:00
parent 107c46cb7a
commit b2257b613e
4 changed files with 45 additions and 42 deletions

View File

@ -16,7 +16,7 @@ def get_report(module_name, report_name):
Return a specific report from within a module.
"""
module = ReportModule.objects.get(file_path=f'{module_name}.py')
return module.scripts.get(report_name)
return module.reports.get(report_name)
@job('default')

View File

@ -826,13 +826,6 @@ class ReportListView(ContentTypePermissionRequiredMixin, View):
).order_by('name', '-created').distinct('name').defer('data')
}
# for module, report_list in reports.items():
# module_reports = []
# for report in report_list.values():
# report.result = results.get(report.full_name, None)
# module_reports.append(report)
# ret.append((module, module_reports))
return render(request, 'extras/report_list.html', {
'model': ScriptModule,
'report_modules': report_modules,
@ -971,10 +964,6 @@ class ScriptListView(ContentTypePermissionRequiredMixin, View):
).order_by('name', '-created').distinct('name').defer('data')
}
# for _scripts in scripts.values():
# for script in _scripts.values():
# script.result = results.get(script.full_name)
return render(request, 'extras/script_list.html', {
'model': ScriptModule,
'script_modules': script_modules,

View File

@ -44,7 +44,8 @@
<th width="250">Name</th>
<th width="110">Status</th>
<th>Description</th>
<th width="150" class="text-end">Last Run</th>
<th>Last Run</th>
<th>Last Status</th>
<th width="120"></th>
</tr>
</thead>
@ -58,20 +59,25 @@
{% include 'extras/inc/job_label.html' with result=report.result %}
</td>
<td>{{ report.description|markdown|placeholder }}</td>
<td class="text-end">
{% if report.result %}
<a href="{% url 'extras:report_result' job_result_pk=report.result.pk %}">{{ report.result.created|annotated_date }}</a>
{% else %}
<span class="text-muted">Never</span>
{% endif %}
{% with last_result=job_results|get_key:report.full_name %}
{% if last_result %}
<td>
<a href="{% url 'extras:report_result' job_result_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
</td>
<td>
{% badge last_result.get_status_display last_result.get_status_color %}
</td>
{% else %}
<td class="text-muted">Never</td>
<td>{{ ''|placeholder }}</td>
{% endif %}
<td>
{% if perms.extras.run_report %}
<div class="float-end noprint">
<form action="{% url 'extras:report' module=report.module name=report.class_name %}" method="post">
{% csrf_token %}
<button type="submit" name="_run" class="btn btn-primary btn-sm" style="width: 110px">
{% if report.result %}
{% if last_result %}
<i class="mdi mdi-replay"></i> Run Again
{% else %}
<i class="mdi mdi-play"></i> Run Report
@ -81,6 +87,7 @@
</div>
{% endif %}
</td>
{% endwith %}
</tr>
{% for method, stats in report.result.data.items %}
<tr>

View File

@ -43,7 +43,8 @@
<th width="250">Name</th>
<th width="110">Status</th>
<th>Description</th>
<th class="text-end">Last Run</th>
<th>Last Run</th>
<th class="text-end">Status</th>
</tr>
</thead>
<tbody>
@ -58,13 +59,19 @@
<td>
{{ script_class.Meta.description|markdown|placeholder }}
</td>
{% if script_class.result %}
{% with last_result=job_results|get_key:script_class.full_name %}
{% if last_result %}
<td>
<a href="{% url 'extras:script_result' job_result_pk=last_result.pk %}">{{ last_result.created|annotated_date }}</a>
</td>
<td class="text-end">
<a href="{% url 'extras:script_result' job_result_pk=script_class.result.pk %}">{{ script_class.result.created|annotated_date }}</a>
{% badge last_result.get_status_display last_result.get_status_color %}
</td>
{% else %}
<td class="text-end text-muted">Never</td>
<td class="text-muted">Never</td>
<td class="text-end">{{ ''|placeholder }}</td>
{% endif %}
{% endwith %}
</tr>
{% endfor %}
</tbody>