diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 532e32636..75591c6ae 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -1163,11 +1163,23 @@ class ScriptResultView(ContentTypePermissionRequiredMixin, View): module = job.object script = module.scripts[job.name]() + if 'logs' in job.data: + legacy_script = False + legacy_report = False + elif 'log' in job.data: + legacy_script = True + legacy_report = False + else: + legacy_script = False + legacy_report = True + # If this is an HTMX request, return only the result HTML if request.htmx: response = render(request, 'extras/htmx/script_result.html', { 'script': script, 'job': job, + 'legacy_script': legacy_script, + 'legacy_report': legacy_report, }) if job.completed or not job.started: response.status_code = 286 @@ -1176,6 +1188,8 @@ class ScriptResultView(ContentTypePermissionRequiredMixin, View): return render(request, 'extras/script_result.html', { 'script': script, 'job': job, + 'legacy_script': legacy_script, + 'legacy_report': legacy_report, }) diff --git a/netbox/templates/extras/htmx/legacy_report_result.html b/netbox/templates/extras/htmx/legacy_report_result.html new file mode 100644 index 000000000..e6b6caf73 --- /dev/null +++ b/netbox/templates/extras/htmx/legacy_report_result.html @@ -0,0 +1,81 @@ +{% load humanize %} +{% load helpers %} +{% load i18n %} + +

+ {% if job.started %} + {% trans "Started" %}: {{ job.started|annotated_date }} + {% elif job.scheduled %} + {% trans "Scheduled for" %}: {{ job.scheduled|annotated_date }} ({{ job.scheduled|naturaltime }}) + {% else %} + {% trans "Created" %}: {{ job.created|annotated_date }} + {% endif %} + {% if job.completed %} + {% trans "Duration" %}: {{ job.duration }} + {% endif %} + {% badge job.get_status_display job.get_status_color %} +

+{% if job.completed %} +
+
{% trans "Report Methods" %}
+
+ + {% for method, data in job.data.items %} + + + + + {% endfor %} +
{{ method }} + {{ data.success }} + {{ data.info }} + {{ data.warning }} + {{ data.failure }} +
+
+
+
+
{% trans "Report Results" %}
+
+ + + + + + + + + + + {% for method, data in job.data.items %} + + + + {% for time, level, obj, url, message in data.log %} + + + + + + + {% endfor %} + {% endfor %} + +
{% trans "Time" %}{% trans "Level" %}{% trans "Object" %}{% trans "Message" %}
+ {{ method }} +
{{ time }} + + + {% if obj and url %} + {{ obj }} + {% elif obj %} + {{ obj }} + {% else %} + {{ ''|placeholder }} + {% endif %} + {{ message|markdown }}
+
+
+{% elif job.started %} + {% include 'extras/inc/result_pending.html' %} +{% endif %} diff --git a/netbox/templates/extras/htmx/legacy_script_result.html b/netbox/templates/extras/htmx/legacy_script_result.html new file mode 100644 index 000000000..ddc9b05f6 --- /dev/null +++ b/netbox/templates/extras/htmx/legacy_script_result.html @@ -0,0 +1,58 @@ +{% load humanize %} +{% load helpers %} +{% load log_levels %} +{% load i18n %} + +

+ {% if job.started %} + {% trans "Started" %}: {{ job.started|annotated_date }} + {% elif job.scheduled %} + {% trans "Scheduled for" %}: {{ job.scheduled|annotated_date }} ({{ job.scheduled|naturaltime }}) + {% else %} + {% trans "Created" %}: {{ job.created|annotated_date }} + {% endif %} + {% if job.completed %} + {% trans "Duration" %}: {{ job.duration }} + {% endif %} + {% badge job.get_status_display job.get_status_color %} +

+{% if job.completed %} +
+
{% trans "Script Log" %}
+
+ + + + + + + {% for log in job.data.log %} + + + + + + {% empty %} + + + + {% endfor %} +
{% trans "Line" %}{% trans "Level" %}{% trans "Message" %}
{{ forloop.counter }}{% log_level log.status %}{{ log.message|markdown }}
+ {% trans "No log output" %} +
+
+ {% if execution_time %} + + {% endif %} +
+

{% trans "Output" %}

+ {% if job.data.output %} +
{{ job.data.output }}
+ {% else %} +

{% trans "None" %}

+ {% endif %} +{% elif job.started %} + {% include 'extras/inc/result_pending.html' %} +{% endif %} diff --git a/netbox/templates/extras/script_result.html b/netbox/templates/extras/script_result.html index 985c58d63..02a01149c 100644 --- a/netbox/templates/extras/script_result.html +++ b/netbox/templates/extras/script_result.html @@ -44,7 +44,13 @@
- {% include 'extras/htmx/script_result.html' %} + {% if legacy_script %} + {% include 'extras/htmx/legacy_script_result.html' %} + {% elif legacy_report %} + {% include 'extras/htmx/legacy_report_result.html' %} + {% else %} + {% include 'extras/htmx/script_result.html' %} + {% endif %}