Skip to content

Commit 8c7b0cf

Browse files
committed
Close #2892: Extend admin UI to allow deleting old report results
1 parent 0cf94cf commit 8c7b0cf

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

docs/release-notes/version-2.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Enhancements
44

5+
* [#2892](https://github.com/netbox-community/netbox/issues/2892) - Extend admin UI to allow deleting old report results
56
* [#3062](https://github.com/netbox-community/netbox/issues/3062) - Add `assigned_to_interface` filter for IP addresses
67
* [#3461](https://github.com/netbox-community/netbox/issues/3461) - Fail gracefully on custom link rendering exception
78
* [#3705](https://github.com/netbox-community/netbox/issues/3705) - Provide request context when executing custom scripts

netbox/extras/admin.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
from netbox.admin import admin_site
55
from utilities.forms import LaxURLField
6-
from .models import CustomField, CustomFieldChoice, CustomLink, Graph, ExportTemplate, TopologyMap, Webhook
6+
from .models import (
7+
CustomField, CustomFieldChoice, CustomLink, Graph, ExportTemplate, ReportResult, TopologyMap, Webhook,
8+
)
9+
from .reports import get_report
710

811

912
def order_content_types(field):
@@ -166,6 +169,36 @@ class ExportTemplateAdmin(admin.ModelAdmin):
166169
form = ExportTemplateForm
167170

168171

172+
#
173+
# Reports
174+
#
175+
176+
@admin.register(ReportResult, site=admin_site)
177+
class ReportResultAdmin(admin.ModelAdmin):
178+
list_display = [
179+
'report', 'active', 'created', 'user', 'passing',
180+
]
181+
fields = [
182+
'report', 'user', 'passing', 'data',
183+
]
184+
list_filter = [
185+
'failed',
186+
]
187+
readonly_fields = fields
188+
189+
def has_add_permission(self, request):
190+
return False
191+
192+
def active(self, obj):
193+
module, report_name = obj.report.split('.')
194+
return True if get_report(module, report_name) else False
195+
active.boolean = True
196+
197+
def passing(self, obj):
198+
return not obj.failed
199+
passing.boolean = True
200+
201+
169202
#
170203
# Topology maps
171204
#

netbox/extras/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,13 @@ class ReportResult(models.Model):
915915
class Meta:
916916
ordering = ['report']
917917

918+
def __str__(self):
919+
return "{} {} at {}".format(
920+
self.report,
921+
"passed" if not self.failed else "failed",
922+
self.created
923+
)
924+
918925

919926
#
920927
# Change logging

0 commit comments

Comments
 (0)