context_processors: Use active menu urls to decide what to highlight

- We are using submenu.url to check for specific URLs and then highlight a menu
item. This is somewhat incorrect due to string search and not generic enough. We
have another mechanism 'active_menu_urls' to perform this. Improve and use this
instead.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa committed 2024-10-16 21:08:00 -07:00
1 parent 5fa9bf2928
commit d605907bbe
3 files changed
+13 -11

No files matched your search

+6 -6
View File
@@ -23,7 +23,7 @@ def test_common(Notification, load_cfg):
"""Verify that the common() function returns the correct values."""
request = HttpRequest()
request.path = '/aaa/bbb/ccc/'
request.path = '/plinth/aaa/bbb/ccc/'
request.user = Mock()
request.user.groups.filter().exists = Mock(return_value=True)
request.session = MagicMock()
@@ -41,7 +41,7 @@ def test_common(Notification, load_cfg):
urls = response['active_menu_urls']
assert urls is not None
assert ['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'] == urls
assert ['/plinth/aaa/', '/plinth/aaa/bbb/', '/plinth/aaa/bbb/ccc/'] == urls
assert response['user_is_admin']
@@ -57,10 +57,10 @@ def test_common_border_conditions(Notification):
response = cp.common(request)
assert response['active_menu_urls'] == []
request.path = '/'
request.path = '/plinth/'
response = cp.common(request)
assert response['active_menu_urls'] == ['/']
assert response['active_menu_urls'] == []
request.path = '/aaa/bbb'
request.path = '/plinth/aaa/bbb/ccc'
response = cp.common(request)
assert response['active_menu_urls'] == ['/', '/aaa/']
assert response['active_menu_urls'] == ['/plinth/aaa/', '/plinth/aaa/bbb/']