Files
Netbox-Utilities/netbox_utilities/runtime.py
T
MrBlakeandClaude Sonnet 5 3768417be6 feat: add offline SVG export for rack elevations
Adds a "SVG offline" download button on the rack detail page. It
reuses NetBox's own rack-elevation REST endpoint to render the SVG,
then strips embedded <a>/xlink:href links (which point at internal,
relative NetBox URLs and are useless once the file is saved) so the
result renders identically when opened standalone in any SVG viewer.

Gated by the new offline_svg_export_enabled plugin setting (on by
default).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-17 14:22:04 +02:00

58 lines
1.8 KiB
Python

from django.core.cache import cache
from django.db import OperationalError, ProgrammingError
from netbox.plugins import get_plugin_config
from .models import UtilitiesSettings
SETTINGS_CACHE_KEY = "netbox_utilities.runtime_settings.v2"
def navigation_customization_enabled():
return bool(get_plugin_config("netbox_utilities", "navigation_customization_enabled"))
def connection_vlans_enabled():
return bool(get_plugin_config("netbox_utilities", "connection_vlans_enabled"))
def offline_svg_export_enabled():
return bool(get_plugin_config("netbox_utilities", "offline_svg_export_enabled"))
def tenant_filter_enabled():
if not get_plugin_config("netbox_utilities", "tenant_filter_enabled"):
return False
return bool(_get_database_settings()["tenant_filter_enabled"])
def tenant_required():
if not get_plugin_config("netbox_utilities", "tenant_required"):
return False
return bool(_get_database_settings()["tenant_required"])
def _get_database_settings():
runtime_settings = cache.get(SETTINGS_CACHE_KEY)
if runtime_settings is None:
try:
runtime_settings = (
UtilitiesSettings.objects.filter(singleton_id=1)
.values("tenant_filter_enabled", "tenant_required")
.first()
)
except (OperationalError, ProgrammingError):
# The middleware can be imported before the first plugin migration.
runtime_settings = None
runtime_settings = runtime_settings or {
"tenant_filter_enabled": True,
"tenant_required": True,
}
cache.set(SETTINGS_CACHE_KEY, runtime_settings, timeout=30)
return runtime_settings
def clear_runtime_settings_cache():
cache.delete(SETTINGS_CACHE_KEY)