From f876e9ed043ef0733e9f22d554f33d0f8689ded7 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 20 Feb 2023 20:16:49 -0500 Subject: [PATCH] Clean up widgets --- netbox/extras/constants.py | 6 +++--- netbox/extras/dashboard/utils.py | 2 +- netbox/extras/dashboard/widgets.py | 17 +++++++++++++++-- .../extras/dashboard/widgets/objectcounts.html | 4 +++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/netbox/extras/constants.py b/netbox/extras/constants.py index 2a47c15e2..e1ce7b713 100644 --- a/netbox/extras/constants.py +++ b/netbox/extras/constants.py @@ -7,8 +7,8 @@ DEFAULT_DASHBOARD = [ 'widget': 'extras.ObjectCountsWidget', 'width': 4, 'height': 3, + 'title': 'IPAM', 'config': { - 'title': 'IPAM', 'models': [ 'ipam.Aggregate', 'ipam.Prefix', @@ -21,8 +21,8 @@ DEFAULT_DASHBOARD = [ 'widget': 'extras.ObjectCountsWidget', 'width': 4, 'height': 3, + 'title': 'DCIM', 'config': { - 'title': 'DCIM', 'models': [ 'dcim.Site', 'dcim.Rack', @@ -36,7 +36,7 @@ DEFAULT_DASHBOARD = [ 'width': 4, 'height': 3, 'config': { - 'content': 'Welcome to NetBox!' + 'content': 'Welcome to **NetBox**!' } }, { diff --git a/netbox/extras/dashboard/utils.py b/netbox/extras/dashboard/utils.py index 1da34b72f..345b00ff6 100644 --- a/netbox/extras/dashboard/utils.py +++ b/netbox/extras/dashboard/utils.py @@ -28,7 +28,6 @@ def get_dashboard(user): config = user.config.get('dashboard') else: config = get_default_dashboard_config() - print(config) if not user.is_anonymous: user.config.set('dashboard', config, commit=True) @@ -60,6 +59,7 @@ def get_default_dashboard_config(): }) config['widgets'][id] = { 'class': widget['widget'], + 'title': widget.get('title'), 'config': widget.get('config', {}), } diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index 776e75d90..5107b276d 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -2,8 +2,10 @@ import uuid from django.contrib.contenttypes.models import ContentType from django.template.loader import render_to_string +from django.utils.safestring import mark_safe from django.utils.translation import gettext as _ +from utilities.templatetags.builtins.filters import render_markdown from .utils import register_widget __all__ = ( @@ -15,6 +17,8 @@ __all__ = ( class DashboardWidget: + title = None + description = None width = 4 height = 3 @@ -45,14 +49,23 @@ class DashboardWidget: @register_widget class StaticContentWidget(DashboardWidget): + description = _('Display some arbitrary custom content. Markdown is supported.') + default_content = """ +
+
Empty
+
+ """ def render(self, request): - return self.config.get('content', 'Empty!') + if content := self.config.get('content'): + return render_markdown(content) + return mark_safe(self.default_content) @register_widget class ObjectCountsWidget(DashboardWidget): title = _('Objects') + description = _('Display a set of NetBox models and the number of objects created for each type.') template_name = 'extras/dashboard/widgets/objectcounts.html' def render(self, request): @@ -70,9 +83,9 @@ class ObjectCountsWidget(DashboardWidget): @register_widget class ChangeLogWidget(DashboardWidget): + title = _('Change Log') width = 12 height = 4 - title = _('Change log') template_name = 'extras/dashboard/widgets/changelog.html' def render(self, request): diff --git a/netbox/templates/extras/dashboard/widgets/objectcounts.html b/netbox/templates/extras/dashboard/widgets/objectcounts.html index 85fa4d389..d75d88218 100644 --- a/netbox/templates/extras/dashboard/widgets/objectcounts.html +++ b/netbox/templates/extras/dashboard/widgets/objectcounts.html @@ -1,7 +1,9 @@ +{% load helpers %} + {% if counts %}
{% for model, count in counts %} - +
{{ model|meta:"verbose_name_plural"|bettertitle }}
{{ count }}