context_processors.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from django.conf import settings as django_settings
  2. from netbox.config import get_config
  3. from netbox.registry import registry as registry_
  4. __all__ = (
  5. 'config',
  6. 'preferences',
  7. 'registry',
  8. 'settings',
  9. )
  10. def config(request):
  11. """
  12. Adds NetBox configuration parameters to the template context. Example: {{ config.BANNER_LOGIN }}
  13. """
  14. return {
  15. 'config': get_config(),
  16. }
  17. def preferences(request):
  18. """
  19. Adds preferences for the current user (if authenticated) to the template context.
  20. Example: {{ preferences|get_key:"pagination.placement" }}
  21. """
  22. user_preferences = request.user.config if request.user.is_authenticated else {}
  23. return {
  24. 'preferences': user_preferences,
  25. }
  26. def registry(request):
  27. """
  28. Adds NetBox registry items to the template context. Example: {{ registry.models.core }}
  29. """
  30. return {
  31. 'registry': registry_,
  32. }
  33. def settings(request):
  34. """
  35. Adds Django settings to the template context. Example: {{ settings.DEBUG }}
  36. """
  37. return {
  38. 'settings': django_settings,
  39. }