Skip to content

Commit 7a2ff96

Browse files
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 <[email protected]>
1 parent 814b699 commit 7a2ff96

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

netbox/extras/dashboard/widgets.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,13 @@ def render(self, request):
183183
for model in get_models_from_content_types(self.config['models']):
184184
permission = get_permission_for_model(model, 'view')
185185
if request.user.has_perm(permission):
186-
url = reverse(get_viewname(model, 'list'))
186+
try:
187+
url = reverse(get_viewname(model, 'list'))
188+
except NoReverseMatch:
189+
url = None
187190
qs = model.objects.restrict(request.user, 'view')
188191
# Apply any specified filters
189-
if filters := self.config.get('filters'):
192+
if url and (filters := self.config.get('filters')):
190193
params = dict_to_querydict(filters)
191194
filterset = getattr(resolve(url).func.view_class, 'filterset', None)
192195
qs = filterset(params, qs).qs

netbox/templates/extras/dashboard/widgets/objectcounts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% if counts %}
44
<div class="list-group list-group-flush">
55
{% for model, count, url in counts %}
6-
<a href="{{ url }}" class="list-group-item list-group-item-action px-1 py-2">
6+
<a {% if url %}href="{{ url }}" {% endif %}class="list-group-item list-group-item-action px-1 py-2">
77
<div class="d-flex w-100 justify-content-between align-items-center">
88
{{ model|meta:"verbose_name_plural"|bettertitle }}
99
{% if count is None %}

0 commit comments

Comments
 (0)