-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #15942: Refactor settings_and_registry() context processor
- Loading branch information
1 parent
f8cf2a3
commit 4150442
Showing
2 changed files
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters