mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Fixes #18782: properly check if htmx_url is None
If this is done incorrently, then the string formatting operation turns `htmx_url` into a string and the test in the template fails.
This commit is contained in:
parent
f9c8d12a51
commit
528248b560
@ -257,7 +257,7 @@ class ObjectListWidget(DashboardWidget):
|
||||
parameters['per_page'] = page_size
|
||||
parameters['embedded'] = True
|
||||
|
||||
if parameters:
|
||||
if parameters and htmx_url is not None:
|
||||
try:
|
||||
htmx_url = f'{htmx_url}?{urlencode(parameters, doseq=True)}'
|
||||
except ValueError:
|
||||
|
43
netbox/extras/tests/test_dashboard.py
Normal file
43
netbox/extras/tests/test_dashboard.py
Normal file
@ -0,0 +1,43 @@
|
||||
from django.test import tag, TestCase
|
||||
|
||||
from extras.dashboard.widgets import ObjectListWidget
|
||||
|
||||
|
||||
class ObjectListWidgetTests(TestCase):
|
||||
@tag('regression')
|
||||
def test_widget_fails_gracefully(self):
|
||||
"""
|
||||
Example:
|
||||
'2829fd9b-5dee-4c9a-81f2-5bd84c350a27': {
|
||||
'class': 'extras.ObjectListWidget',
|
||||
'color': 'indigo',
|
||||
'title': 'Object List',
|
||||
'config': {
|
||||
'model': 'extras.notification',
|
||||
'page_size': None,
|
||||
'url_params': None
|
||||
}
|
||||
}
|
||||
"""
|
||||
config = {
|
||||
# 'class': 'extras.ObjectListWidget', # normally popped off, left for clarity
|
||||
'color': 'yellow',
|
||||
'title': 'this should fail',
|
||||
'config': {
|
||||
'model': 'extras.notification',
|
||||
'page_size': None,
|
||||
'url_params': None,
|
||||
},
|
||||
}
|
||||
|
||||
class Request:
|
||||
class User:
|
||||
def has_perm(self, *args, **kwargs):
|
||||
return True
|
||||
|
||||
user = User()
|
||||
|
||||
mock_request = Request()
|
||||
widget = ObjectListWidget(id='2829fd9b-5dee-4c9a-81f2-5bd84c350a27', **config)
|
||||
rendered = widget.render(mock_request)
|
||||
self.assertTrue('Unable to load content. Invalid view name:' in rendered)
|
Loading…
Reference in New Issue
Block a user