diff --git a/netbox/netbox/context_processors.py b/netbox/netbox/context_processors.py index ce4f8c45e..3065855e6 100644 --- a/netbox/netbox/context_processors.py +++ b/netbox/netbox/context_processors.py @@ -1,18 +1,50 @@ from django.conf import settings as django_settings from netbox.config import get_config -from netbox.registry import registry +from netbox.registry import registry as registry_ + +__all__ = ( + 'config', + 'preferences', + 'registry', + 'settings', +) -def settings_and_registry(request): +def config(request): """ - Expose Django settings and NetBox registry stores in the template context. Example: {{ settings.DEBUG }} + Adds NetBox configuration parameters to the template context. Example: {{ config.BANNER_LOGIN }} + """ + return { + 'config': get_config(), + } + + +def preferences(request): + """ + Adds preferences for the current user (if authenticated) to the template context. + Example: {{ preferences|get_key:"pagination.placement" }} """ user_preferences = request.user.config if request.user.is_authenticated else {} return { - 'settings': django_settings, - 'config': get_config(), - 'registry': registry, 'preferences': user_preferences, 'htmx_navigation': user_preferences.get('ui.htmx_navigation', False) == 'true' } + + +def registry(request): + """ + Adds NetBox registry items to the template context. Example: {{ registry.models.core }} + """ + return { + 'registry': registry_, + } + + +def settings(request): + """ + Adds Django settings to the template context. Example: {{ settings.DEBUG }} + """ + return { + 'settings': django_settings, + } diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index d5cded728..965bc0bc7 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -409,7 +409,10 @@ TEMPLATES = [ 'django.template.context_processors.media', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', - 'netbox.context_processors.settings_and_registry', + 'netbox.context_processors.settings', + 'netbox.context_processors.config', + 'netbox.context_processors.registry', + 'netbox.context_processors.preferences', ], }, },