Coverage for utilities/templatetags/navigation.py: 79%

26 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from django import template 

2 

3from netbox.navigation.menu import get_menus 

4 

5__all__ = ( 

6 'nav', 

7) 

8 

9 

10register = template.Library() 

11 

12 

13@register.inclusion_tag("navigation/menu.html", takes_context=True) 

14def nav(context): 

15 """ 

16 Render the navigation menu. 

17 """ 

18 user = context['request'].user 

19 nav_items = [] 

20 

21 # Construct the navigation menu based upon the current user's permissions 

22 for menu in get_menus(): 

23 groups = [] 

24 for group in menu.groups: 

25 items = [] 

26 for item in group.items: 

27 if getattr(item, 'auth_required', False) and not user.is_authenticated: 27 ↛ 28line 27 didn't jump to line 28 because the condition on line 27 was never true

28 continue 

29 if not user.has_perms(item.permissions): 

30 continue 

31 if item.staff_only and not user.is_superuser: 31 ↛ 33line 31 didn't jump to line 33 because the condition on line 31 was always true

32 continue 

33 buttons = [ 

34 button for button in item.buttons if user.has_perms(button.permissions) 

35 ] 

36 items.append((item, buttons)) 

37 if items: 37 ↛ 38line 37 didn't jump to line 38 because the condition on line 37 was never true

38 groups.append((group, items)) 

39 if groups: 39 ↛ 40line 39 didn't jump to line 40 because the condition on line 39 was never true

40 nav_items.append((menu, groups)) 

41 

42 return { 

43 'nav_items': nav_items, 

44 }