From 7a2ff96abe3792e740e1d7e630c7cbd34e191b53 Mon Sep 17 00:00:00 2001 From: Brian Candler Date: Tue, 3 Sep 2024 14:38:06 +0100 Subject: [PATCH] Hide exception in ObjectCountsWidget for models without a `xxx_list` view function (#17342) * Hide exception in ObjectCountsWidget for models without a `xxx_list` view function Fixes #17341 * Disable hyperlink for invalid view names --------- Co-authored-by: Jeremy Stretch --- netbox/extras/dashboard/widgets.py | 7 +++++-- .../templates/extras/dashboard/widgets/objectcounts.html | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index df41cd34b..d23919d9e 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -183,10 +183,13 @@ class ObjectCountsWidget(DashboardWidget): for model in get_models_from_content_types(self.config['models']): permission = get_permission_for_model(model, 'view') if request.user.has_perm(permission): - url = reverse(get_viewname(model, 'list')) + try: + url = reverse(get_viewname(model, 'list')) + except NoReverseMatch: + url = None qs = model.objects.restrict(request.user, 'view') # Apply any specified filters - if filters := self.config.get('filters'): + if url and (filters := self.config.get('filters')): params = dict_to_querydict(filters) filterset = getattr(resolve(url).func.view_class, 'filterset', None) qs = filterset(params, qs).qs diff --git a/netbox/templates/extras/dashboard/widgets/objectcounts.html b/netbox/templates/extras/dashboard/widgets/objectcounts.html index 6110aa4c0..70b71059f 100644 --- a/netbox/templates/extras/dashboard/widgets/objectcounts.html +++ b/netbox/templates/extras/dashboard/widgets/objectcounts.html @@ -3,7 +3,7 @@ {% if counts %}