mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 04:02:52 -06:00
Fixes #17700: Fix warning when no scripts are found within a script module
This commit is contained in:
parent
5f94dff815
commit
f00a93c066
@ -37,101 +37,104 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</h2>
|
</h2>
|
||||||
{% if module.scripts %}
|
{% with scripts=module.scripts.all %}
|
||||||
<table class="table table-hover scripts">
|
{% if scripts %}
|
||||||
<thead>
|
<table class="table table-hover scripts">
|
||||||
<tr>
|
<thead>
|
||||||
<th>{% trans "Name" %}</th>
|
<tr>
|
||||||
<th>{% trans "Description" %}</th>
|
<th>{% trans "Name" %}</th>
|
||||||
<th>{% trans "Last Run" %}</th>
|
<th>{% trans "Description" %}</th>
|
||||||
<th>{% trans "Status" %}</th>
|
<th>{% trans "Last Run" %}</th>
|
||||||
<th></th>
|
<th>{% trans "Status" %}</th>
|
||||||
</tr>
|
<th></th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
</thead>
|
||||||
{% for script in module.scripts.all %}
|
<tbody>
|
||||||
{% with last_job=script.get_latest_jobs|first %}
|
{% for script in scripts %}
|
||||||
<tr>
|
{% with last_job=script.get_latest_jobs|first %}
|
||||||
<td>
|
<tr>
|
||||||
{% if script.is_executable %}
|
<td>
|
||||||
<a href="{% url 'extras:script' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
|
{% if script.is_executable %}
|
||||||
|
<a href="{% url 'extras:script' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'extras:script_jobs' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
|
||||||
|
<span class="text-danger">
|
||||||
|
<i class="mdi mdi-alert" title="{% trans "Script is no longer present in the source file" %}"></i>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td>{{ script.python_class.Meta.description|markdown|placeholder }}</td>
|
||||||
|
{% if last_job %}
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|isodatetime }}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{% badge last_job.get_status_display last_job.get_status_color %}
|
||||||
|
</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{% url 'extras:script_jobs' script.pk %}" id="{{ script.module }}.{{ script.class_name }}">{{ script.python_class.name }}</a>
|
<td class="text-muted">{% trans "Never" %}</td>
|
||||||
<span class="text-danger">
|
<td>{{ ''|placeholder }}</td>
|
||||||
<i class="mdi mdi-alert" title="{% trans "Script is no longer present in the source file" %}"></i>
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
<td>
|
||||||
<td>{{ script.python_class.Meta.description|markdown|placeholder }}</td>
|
{% if request.user|can_run:script and script.is_executable %}
|
||||||
|
<div class="float-end d-print-none">
|
||||||
|
<form action="{% url 'extras:script' script.pk %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit" name="_run" class="btn btn-primary btn-sm">
|
||||||
|
{% if last_job %}
|
||||||
|
<i class="mdi mdi-replay"></i> {% trans "Run Again" %}
|
||||||
|
{% else %}
|
||||||
|
<i class="mdi mdi-play"></i> {% trans "Run Script" %}
|
||||||
|
{% endif %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
{% if last_job %}
|
{% if last_job %}
|
||||||
<td>
|
{% for test_name, data in last_job.data.tests.items %}
|
||||||
<a href="{% url 'extras:script_result' job_pk=last_job.pk %}">{{ last_job.created|isodatetime }}</a>
|
<tr>
|
||||||
</td>
|
<td colspan="4" class="method">
|
||||||
<td>
|
<span class="ps-3">{{ test_name }}</span>
|
||||||
{% badge last_job.get_status_display last_job.get_status_color %}
|
</td>
|
||||||
</td>
|
<td class="text-end text-nowrap script-stats">
|
||||||
{% else %}
|
<span class="badge text-bg-success">{{ data.success }}</span>
|
||||||
<td class="text-muted">{% trans "Never" %}</td>
|
<span class="badge text-bg-info">{{ data.info }}</span>
|
||||||
<td>{{ ''|placeholder }}</td>
|
<span class="badge text-bg-warning">{{ data.warning }}</span>
|
||||||
|
<span class="badge text-bg-danger">{{ data.failure }}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% elif not last_job.data.log %}
|
||||||
|
{# legacy #}
|
||||||
|
{% for method, stats in last_job.data.items %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="method">
|
||||||
|
<span class="ps-3">{{ method }}</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-end text-nowrap report-stats">
|
||||||
|
<span class="badge bg-success">{{ stats.success }}</span>
|
||||||
|
<span class="badge bg-info">{{ stats.info }}</span>
|
||||||
|
<span class="badge bg-warning">{{ stats.warning }}</span>
|
||||||
|
<span class="badge bg-danger">{{ stats.failure }}</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>
|
{% endwith %}
|
||||||
{% if request.user|can_run:script and script.is_executable %}
|
{% endfor %}
|
||||||
<div class="float-end d-print-none">
|
</tbody>
|
||||||
<form action="{% url 'extras:script' script.pk %}" method="post">
|
</table>
|
||||||
{% csrf_token %}
|
{% else %}
|
||||||
<button type="submit" name="_run" class="btn btn-primary btn-sm">
|
<div class="card-body">
|
||||||
{% if last_job %}
|
<div class="alert alert-warning" role="alert">
|
||||||
<i class="mdi mdi-replay"></i> {% trans "Run Again" %}
|
<i class="mdi mdi-alert"></i>
|
||||||
{% else %}
|
{% blocktrans with module=module.name %}Could not load scripts from module {{ module }}{% endblocktrans %}
|
||||||
<i class="mdi mdi-play"></i> {% trans "Run Script" %}
|
</div>
|
||||||
{% endif %}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% if last_job %}
|
|
||||||
{% for test_name, data in last_job.data.tests.items %}
|
|
||||||
<tr>
|
|
||||||
<td colspan="4" class="method">
|
|
||||||
<span class="ps-3">{{ test_name }}</span>
|
|
||||||
</td>
|
|
||||||
<td class="text-end text-nowrap script-stats">
|
|
||||||
<span class="badge text-bg-success">{{ data.success }}</span>
|
|
||||||
<span class="badge text-bg-info">{{ data.info }}</span>
|
|
||||||
<span class="badge text-bg-warning">{{ data.warning }}</span>
|
|
||||||
<span class="badge text-bg-danger">{{ data.failure }}</span>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
{% elif not last_job.data.log %}
|
|
||||||
{# legacy #}
|
|
||||||
{% for method, stats in last_job.data.items %}
|
|
||||||
<tr>
|
|
||||||
<td colspan="4" class="method">
|
|
||||||
<span class="ps-3">{{ method }}</span>
|
|
||||||
</td>
|
|
||||||
<td class="text-end text-nowrap report-stats">
|
|
||||||
<span class="badge bg-success">{{ stats.success }}</span>
|
|
||||||
<span class="badge bg-info">{{ stats.info }}</span>
|
|
||||||
<span class="badge bg-warning">{{ stats.warning }}</span>
|
|
||||||
<span class="badge bg-danger">{{ stats.failure }}</span>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endwith %}
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
{% else %}
|
|
||||||
<div class="card-body">
|
|
||||||
<div class="alert alert-warning" role="alert">
|
|
||||||
<i class="mdi mdi-alert"></i> Could not load scripts from {{ module.name }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<div class="alert alert-info" role="alert">
|
<div class="alert alert-info" role="alert">
|
||||||
|
Loading…
Reference in New Issue
Block a user