mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Initial work on #11890 * Consolidate get_scripts() and get_reports() functions * Introduce proxy models for script & report modules * Add add/delete views for reports & scripts * Add deletion links for modules * Enable resolving scripts/reports from module class * Remove get_modules() utility function * Show results in report/script lists * Misc cleanup * Fix file uploads * Support automatic migration for submodules * Fix module child ordering * Template cleanup * Remove ManagedFile views * Move is_script(), is_report() into extras.utils * Fix URLs for nested reports & scripts * Misc cleanup
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
{% if result.completed %}
|
||||
Duration: <strong>{{ result.duration }}</strong>
|
||||
{% endif %}
|
||||
<span id="pending-result-label">{% include 'extras/inc/job_label.html' %}</span>
|
||||
<span id="pending-result-label">{% badge result.get_status_display result.get_status_color %}</span>
|
||||
</p>
|
||||
{% if result.completed %}
|
||||
<div class="card">
|
||||
|
@@ -13,7 +13,7 @@
|
||||
{% if result.completed %}
|
||||
Duration: <strong>{{ result.duration }}</strong>
|
||||
{% endif %}
|
||||
<span id="pending-result-label">{% include 'extras/inc/job_label.html' %}</span>
|
||||
<span id="pending-result-label">{% badge result.get_status_display result.get_status_color %}</span>
|
||||
</p>
|
||||
{% if result.completed %}
|
||||
<div class="card mb-3">
|
||||
|
@@ -1,15 +0,0 @@
|
||||
{% if result.status == 'failed' %}
|
||||
<span class="badge bg-danger">Failed</span>
|
||||
{% elif result.status == 'errored' %}
|
||||
<span class="badge bg-danger">Errored</span>
|
||||
{% elif result.status == 'pending' %}
|
||||
<span class="badge bg-info">Pending</span>
|
||||
{% elif result.status == 'scheduled' %}
|
||||
<span class="badge bg-info">Scheduled</span>
|
||||
{% elif result.status == 'running' %}
|
||||
<span class="badge bg-warning">Running</span>
|
||||
{% elif result.status == 'completed' %}
|
||||
<span class="badge bg-success">Completed</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary">N/A</span>
|
||||
{% endif %}
|
@@ -10,7 +10,7 @@
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'extras:report_list' %}">Reports</a></li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'extras:report_list' %}#module.{{ report.module }}">{{ report.module|bettertitle }}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'extras:report_list' %}#module{{ module.pk }}">{{ report.module|bettertitle }}</a></li>
|
||||
{% endblock breadcrumbs %}
|
||||
|
||||
{% block subtitle %}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
{% extends 'base/layout.html' %}
|
||||
{% load buttons %}
|
||||
{% load helpers %}
|
||||
{% load perms %}
|
||||
|
||||
{% block title %}Reports{% endblock %}
|
||||
|
||||
@@ -11,50 +13,67 @@
|
||||
</ul>
|
||||
{% endblock tabs %}
|
||||
|
||||
{% block controls %}
|
||||
<div class="controls">
|
||||
<div class="control-group">
|
||||
{% block extra_controls %}{% endblock %}
|
||||
{% add_button model %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock controls %}
|
||||
|
||||
{% block content-wrapper %}
|
||||
<div class="tab-content">
|
||||
{% if reports %}
|
||||
{% for module, module_reports in reports %}
|
||||
<div class="card">
|
||||
<h5 class="card-header">
|
||||
<a name="module.{{ module }}"></a>
|
||||
<i class="mdi mdi-file-document-outline"></i> {{ module|bettertitle }}
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
<table class="table table-hover table-headings reports">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="250">Name</th>
|
||||
<th width="110">Status</th>
|
||||
<th>Description</th>
|
||||
<th width="150" class="text-end">Last Run</th>
|
||||
<th width="120"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for report in module_reports %}
|
||||
{% for module in report_modules %}
|
||||
<div class="card">
|
||||
<h5 class="card-header" id="module{{ module.pk }}">
|
||||
{% if perms.extras.delete_reportmodule %}
|
||||
<div class="float-end">
|
||||
<a href="{% url 'extras:reportmodule_delete' pk=module.pk %}" class="btn btn-danger btn-sm">
|
||||
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<i class="mdi mdi-file-document-outline"></i> {{ module.name|bettertitle }}
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
{% include 'inc/sync_warning.html' with object=module %}
|
||||
<table class="table table-hover table-headings reports">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="250">Name</th>
|
||||
<th>Description</th>
|
||||
<th>Last Run</th>
|
||||
<th>Status</th>
|
||||
<th width="120"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for report_name, report in module.reports.items %}
|
||||
{% with last_result=job_results|get_key:report.full_name %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'extras:report' module=report.module name=report.class_name %}" id="{{ report.module }}.{{ report.class_name }}">{{ report.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{% include 'extras/inc/job_label.html' with result=report.result %}
|
||||
<a href="{% url 'extras:report' module=module.path name=report.class_name %}" id="{{ report.module }}.{{ report.class_name }}">{{ report.name }}</a>
|
||||
</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 %}
|
||||
</td>
|
||||
{% 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
|
||||
@@ -65,7 +84,7 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% for method, stats in report.result.data.items %}
|
||||
{% for method, stats in last_result.data.items %}
|
||||
<tr>
|
||||
<td colspan="4" class="method">
|
||||
<span class="ps-3">{{ method }}</span>
|
||||
@@ -78,19 +97,19 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="alert alert-info" role="alert">
|
||||
<h4 class="alert-heading">No Reports Found</h4>
|
||||
Reports should be saved to <code>{{ settings.REPORTS_ROOT }}</code>.
|
||||
<hr/>
|
||||
<small>This path can be changed by setting <code>REPORTS_ROOT</code> in NetBox's configuration.</small>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock content-wrapper %}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}">Scripts</a></li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}#module.{{ module }}">{{ module|bettertitle }}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'extras:script_list' %}#module{{ module.pk }}">{{ module|bettertitle }}</a></li>
|
||||
{% endblock breadcrumbs %}
|
||||
|
||||
{% block subtitle %}
|
||||
|
@@ -1,8 +1,18 @@
|
||||
{% extends 'base/layout.html' %}
|
||||
{% load buttons %}
|
||||
{% load helpers %}
|
||||
|
||||
{% block title %}Scripts{% endblock %}
|
||||
|
||||
{% block controls %}
|
||||
<div class="controls">
|
||||
<div class="control-group">
|
||||
{% block extra_controls %}{% endblock %}
|
||||
{% add_button model %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock controls %}
|
||||
|
||||
{% block tabs %}
|
||||
<ul class="nav nav-tabs px-3">
|
||||
<li class="nav-item" role="presentation">
|
||||
@@ -13,56 +23,64 @@
|
||||
|
||||
{% block content-wrapper %}
|
||||
<div class="tab-content">
|
||||
{% if scripts %}
|
||||
{% for module, module_scripts in scripts.items %}
|
||||
<div class="card">
|
||||
<h5 class="card-header">
|
||||
<a name="module.{{ module }}"></a>
|
||||
<i class="mdi mdi-file-document-outline"></i> {{ module|bettertitle }}
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
<table class="table table-hover table-headings reports">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="250">Name</th>
|
||||
<th width="110">Status</th>
|
||||
<th>Description</th>
|
||||
<th class="text-end">Last Run</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for class_name, script in module_scripts.items %}
|
||||
{% for module in script_modules %}
|
||||
<div class="card">
|
||||
<h5 class="card-header" id="module{{ module.pk }}">
|
||||
{% if perms.extras.delete_scriptmodule %}
|
||||
<div class="float-end">
|
||||
<a href="{% url 'extras:scriptmodule_delete' pk=module.pk %}" class="btn btn-danger btn-sm">
|
||||
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i> Delete
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<i class="mdi mdi-file-document-outline"></i> {{ module.name|bettertitle }}
|
||||
</h5>
|
||||
<div class="card-body">
|
||||
{% include 'inc/sync_warning.html' with object=module %}
|
||||
<table class="table table-hover table-headings reports">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="250">Name</th>
|
||||
<th>Description</th>
|
||||
<th>Last Run</th>
|
||||
<th class="text-end">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for script_name, script_class in module.scripts.items %}
|
||||
{% with last_result=job_results|get_key:script_class.full_name %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{% url 'extras:script' module=script.root_module name=class_name %}" name="script.{{ class_name }}">{{ script.name }}</a>
|
||||
<a href="{% url 'extras:script' module=module.path name=script_name %}" name="script.{{ script_name }}">{{ script_class.name }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{% include 'extras/inc/job_label.html' with result=script.result %}
|
||||
{{ script_class.Meta.description|markdown|placeholder }}
|
||||
</td>
|
||||
<td>
|
||||
{{ script.Meta.description|markdown|placeholder }}
|
||||
</td>
|
||||
{% if script.result %}
|
||||
{% 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.result.pk %}">{{ script.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 %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
</div>
|
||||
{% empty %}
|
||||
<div class="alert alert-info">
|
||||
<h4 class="alert-heading">No Scripts Found</h4>
|
||||
Scripts should be saved to <code>{{ settings.SCRIPTS_ROOT }}</code>.
|
||||
<hr/>
|
||||
This path can be changed by setting <code>SCRIPTS_ROOT</code> in NetBox's configuration.
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock content-wrapper %}
|
||||
|
Reference in New Issue
Block a user