mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #15942: Refactor settings_and_registry() context processor
This commit is contained in:
@ -1,18 +1,50 @@
|
|||||||
from django.conf import settings as django_settings
|
from django.conf import settings as django_settings
|
||||||
|
|
||||||
from netbox.config import get_config
|
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 {}
|
user_preferences = request.user.config if request.user.is_authenticated else {}
|
||||||
return {
|
return {
|
||||||
'settings': django_settings,
|
|
||||||
'config': get_config(),
|
|
||||||
'registry': registry,
|
|
||||||
'preferences': user_preferences,
|
'preferences': user_preferences,
|
||||||
'htmx_navigation': user_preferences.get('ui.htmx_navigation', False) == 'true'
|
'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,
|
||||||
|
}
|
||||||
|
@ -409,7 +409,10 @@ TEMPLATES = [
|
|||||||
'django.template.context_processors.media',
|
'django.template.context_processors.media',
|
||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'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',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user