Skip to content

Commit

Permalink
Fixes netbox-community#13666: Fix behavior for reports without test m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
JCWasmx86 committed Sep 3, 2023
1 parent 6db6616 commit b020cbd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
20 changes: 18 additions & 2 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,10 +971,26 @@ def get_required_permission(self):

def get(self, request):
report_modules = ReportModule.objects.restrict(request.user)

valid_reports = []
empty_modules = []
for module in report_modules:
number_of_classes = len(m.reports)
valid_classes = 0
for name, cls in module.reports.items():
methods = [func for func in dir(cls) if callable(getattr(cls, func)) and func.startswith('test_')]
if methods:
valid_classes += 1
continue
if number_of_classes == valid_classes:
valid_reports.append(module.id)
else:
empty_modules.append(module.id)
valid_reports_set = report_modules.filter(id__in=valid_reports)
empty_modules_set = report_modules.filter(id__in=empty_modules)
return render(request, 'extras/report_list.html', {
'model': ReportModule,
'report_modules': report_modules,
'report_modules': valid_reports_set,
'empty_modules_set': empty_modules_set,
})


Expand Down
26 changes: 24 additions & 2 deletions netbox/templates/extras/report_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@

{% block content-wrapper %}
<div class="tab-content">
{% if empty_modules_set %}
<div class="card">
<h5 class="card-header" id="">
<i class="mdi mdi-alert"></i> {% trans "Reports without test methods" %}
</h5>
<div class="card-body">
{% for module in empty_modules_set %}
<div id="module{{ module }}">
{% 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> {% trans "Delete" %}
</a>
</div>
{% endif %}
<i class="mdi mdi-file-document-outline"></i> {{ module }}
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% for module in report_modules %}
<div class="card">
<h5 class="card-header" id="module{{ module.pk }}">
Expand Down Expand Up @@ -112,7 +133,8 @@ <h5 class="card-header" id="module{{ module.pk }}">
{% endif %}
</div>
</div>
{% empty %}
{% endfor %}
{% if report_modules|length_is:"0" and empty_modules_set|length_is:"0" %}
<div class="alert alert-info" role="alert">
<h4 class="alert-heading">{% trans "No Reports Found" %}</h4>
{% if perms.extras.add_reportmodule %}
Expand All @@ -122,6 +144,6 @@ <h4 class="alert-heading">{% trans "No Reports Found" %}</h4>
{% endblocktrans %}
{% endif %}
</div>
{% endfor %}
{% endif %}
</div>
{% endblock content-wrapper %}

0 comments on commit b020cbd

Please sign in to comment.