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 <jstretch@netboxlabs.com>
This commit is contained in:
Brian Candler
2024-09-03 14:38:06 +01:00
committed by GitHub
parent 814b699204
commit 7a2ff96abe
2 changed files with 6 additions and 3 deletions

View File

@@ -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