Coverage for netbox/context_processors.py: 100%

14 statements  

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

1from django.conf import settings as django_settings 

2 

3from netbox.config import get_config 

4from netbox.registry import registry as registry_ 

5 

6__all__ = ( 

7 'config', 

8 'preferences', 

9 'registry', 

10 'settings', 

11) 

12 

13 

14def config(request): 

15 """ 

16 Adds NetBox configuration parameters to the template context. Example: {{ config.BANNER_LOGIN }} 

17 """ 

18 return { 

19 'config': get_config(), 

20 } 

21 

22 

23def preferences(request): 

24 """ 

25 Adds preferences for the current user (if authenticated) to the template context. 

26 Example: {{ preferences|get_key:"pagination.placement" }} 

27 """ 

28 config = get_config() 

29 user_preferences = request.user.config if request.user.is_authenticated else {} 

30 return { 

31 'preferences': user_preferences, 

32 'copilot_enabled': ( 

33 config.COPILOT_ENABLED and not django_settings.ISOLATED_DEPLOYMENT and 

34 user_preferences.get('ui.copilot_enabled', False) == 'true' 

35 ), 

36 } 

37 

38 

39def registry(request): 

40 """ 

41 Adds NetBox registry items to the template context. 

42 """ 

43 return { 

44 'registry': registry_, 

45 } 

46 

47 

48def settings(request): 

49 """ 

50 Adds Django settings to the template context. Example: {{ settings.DEBUG }} 

51 """ 

52 return { 

53 'settings': django_settings, 

54 }