From 29fbe6e4ee257ff6ef95fbabbd79728a7637a706 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 5 Apr 2023 08:32:18 -0400 Subject: [PATCH] Closes #12126: Introduce a DEFAULT_DASHBOARD config parameter --- docs/configuration/default-values.md | 45 ++++++++++++++++++++++++++++ netbox/extras/dashboard/utils.py | 6 +++- netbox/netbox/settings.py | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/docs/configuration/default-values.md b/docs/configuration/default-values.md index 6d92858eb..e76930208 100644 --- a/docs/configuration/default-values.md +++ b/docs/configuration/default-values.md @@ -1,5 +1,50 @@ # Default Value Parameters +## DEFAULT_DASHBOARD + +This parameter controls the content and layout of user's default dashboard. Once the dashboard has been created, the user is free to customize it as they please by adding, removing, and reconfiguring widgets. + +This parameter must specify an iterable of dictionaries, each representing a discrete dashboard widget and its configuration. The follow widget attributes are supported: + +* `widget`: Dotted path to the Python class (required) +* `width`: Default widget width (between 1 and 12, inclusive) +* `height`: Default widget height, in rows +* `title`: Widget title +* `color`: Color of the widget's title bar, specified by name +* `config`: Dictionary mapping of any widget configuration parameters + +A brief example configuration is provided below. + +```python +DEFAULT_DASHBOARD = [ + { + 'widget': 'extras.ObjectCountsWidget', + 'width': 4, + 'height': 2, + 'title': 'Organization', + 'config': { + 'models': [ + 'dcim.site', + 'tenancy.tenant', + 'tenancy.contact', + ] + } + }, + { + 'widget': 'extras.ObjectCountsWidget', + 'title': 'IPAM', + 'color': 'blue', + 'config': { + 'models': [ + 'ipam.prefix', + 'ipam.iprange', + 'ipam.ipaddress', + ] + } + }, +] +``` + ## DEFAULT_USER_PREFERENCES !!! tip "Dynamic Configuration Parameter" diff --git a/netbox/extras/dashboard/utils.py b/netbox/extras/dashboard/utils.py index abd731464..f7ffad2b2 100644 --- a/netbox/extras/dashboard/utils.py +++ b/netbox/extras/dashboard/utils.py @@ -1,5 +1,6 @@ import uuid +from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from netbox.registry import registry @@ -54,8 +55,11 @@ def get_dashboard(user): def get_default_dashboard(): from extras.models import Dashboard + dashboard = Dashboard() - for widget in DEFAULT_DASHBOARD: + default_config = settings.DEFAULT_DASHBOARD or DEFAULT_DASHBOARD + + for widget in default_config: id = str(uuid.uuid4()) dashboard.layout.append({ 'id': id, diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 14b00a76f..ee7b4bb9e 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -86,6 +86,7 @@ CSRF_TRUSTED_ORIGINS = getattr(configuration, 'CSRF_TRUSTED_ORIGINS', []) DATE_FORMAT = getattr(configuration, 'DATE_FORMAT', 'N j, Y') DATETIME_FORMAT = getattr(configuration, 'DATETIME_FORMAT', 'N j, Y g:i a') DEBUG = getattr(configuration, 'DEBUG', False) +DEFAULT_DASHBOARD = getattr(configuration, 'DEFAULT_DASHBOARD', None) DEVELOPER = getattr(configuration, 'DEVELOPER', False) DOCS_ROOT = getattr(configuration, 'DOCS_ROOT', os.path.join(os.path.dirname(BASE_DIR), 'docs')) EMAIL = getattr(configuration, 'EMAIL', {})