diff --git a/netbox/extras/dashboard/forms.py b/netbox/extras/dashboard/forms.py index 9c09e6e7b..bb962b464 100644 --- a/netbox/extras/dashboard/forms.py +++ b/netbox/extras/dashboard/forms.py @@ -2,7 +2,8 @@ from django import forms from django.urls import reverse_lazy from netbox.registry import registry -from utilities.forms import BootstrapMixin +from utilities.forms import BootstrapMixin, add_blank_choice +from utilities.choices import ButtonColorChoices __all__ = ( 'DashboardWidgetAddForm', @@ -18,6 +19,10 @@ class DashboardWidgetForm(BootstrapMixin, forms.Form): title = forms.CharField( required=False ) + color = forms.ChoiceField( + choices=add_blank_choice(ButtonColorChoices), + required=False, + ) class DashboardWidgetAddForm(DashboardWidgetForm): diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index 8987f4d06..a3d617e92 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -3,7 +3,6 @@ import uuid from django import forms 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.forms import BootstrapMixin @@ -27,7 +26,7 @@ def get_content_type_labels(): class DashboardWidget: - title = None + default_title = None description = None width = 4 height = 3 @@ -35,11 +34,11 @@ class DashboardWidget: class ConfigForm(forms.Form): pass - def __init__(self, id=None, title=None, config=None, width=None, height=None, x=None, y=None): + def __init__(self, id=None, title=None, color=None, config=None, width=None, height=None, x=None, y=None): self.id = id or uuid.uuid4() self.config = config or {} - if title: - self.title = title + self.title = title or self.default_title + self.color = color if width: self.width = width if height: @@ -56,7 +55,7 @@ class DashboardWidget: self.y = grid_item.get('y') def render(self, request): - raise NotImplementedError("DashboardWidget subclasses must define a render() method.") + raise NotImplementedError(f"{self.__class__} must define a render() method.") @property def name(self): @@ -66,11 +65,6 @@ class DashboardWidget: @register_widget class NoteWidget(DashboardWidget): description = _('Display some arbitrary custom content. Markdown is supported.') - default_content = """ -