|
|
@@ -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 }}
|
|
|
"""
|
|
|
- user_preferences = request.user.config if request.user.is_authenticated else {}
|
|
|
return {
|
|
|
- 'settings': django_settings,
|
|
|
'config': get_config(),
|
|
|
- 'registry': registry,
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+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 {
|
|
|
'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,
|
|
|
+ }
|