From 81c9177c097c2d54e434f011b68a075ed583150b Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 26 Mar 2020 11:26:11 -0400 Subject: [PATCH] Add a default button color --- docs/plugins/development.md | 2 +- netbox/extras/plugins/__init__.py | 9 +++++++-- netbox/utilities/choices.py | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/plugins/development.md b/docs/plugins/development.md index 4a82a3e8d..3b75a8145 100644 --- a/docs/plugins/development.md +++ b/docs/plugins/development.md @@ -311,8 +311,8 @@ A `PluginNavMenuButton` has the following attributes: * `link` - The name of the URL path to which this button links * `title` - The tooltip text (displayed when the mouse hovers over the button) -* `color` - Button color (one of the choices provided by `ButtonColorChoices`) * `icon_class` - Button icon CSS class +* `color` - One of the choices provided by `ButtonColorChoices` (optional) * `permission` - The name of the permission required to display this button (optional) ## Template Content diff --git a/netbox/extras/plugins/__init__.py b/netbox/extras/plugins/__init__.py index 0a5f8de37..c2235c0c6 100644 --- a/netbox/extras/plugins/__init__.py +++ b/netbox/extras/plugins/__init__.py @@ -6,6 +6,7 @@ from django.template.loader import get_template from django.utils.module_loading import import_string from extras.registry import registry +from utilities.choices import ButtonColorChoices # Initialize plugin registry stores @@ -174,13 +175,17 @@ class PluginNavMenuButton: This class represents a button which is a part of the nav menu link item. Note that button colors should come from ButtonColorChoices """ - def __init__(self, link, title, icon_class, color, permission=None): + color = ButtonColorChoices.DEFAULT + + def __init__(self, link, title, icon_class, color=None, permission=None): self.link = link self.title = title self.icon_class = icon_class - self.color = color self.permission = permission + if color is not None: + self.color = color + def register_menu_items(section_name, class_list): """ diff --git a/netbox/utilities/choices.py b/netbox/utilities/choices.py index c38b2d1bf..aba64e63b 100644 --- a/netbox/utilities/choices.py +++ b/netbox/utilities/choices.py @@ -88,7 +88,7 @@ class ButtonColorChoices(ChoiceSet): """ Map standard button color choices to Bootstrap color classes """ - + DEFAULT = 'default' BLUE = 'primary' GREY = 'secondary' GREEN = 'success' @@ -97,6 +97,7 @@ class ButtonColorChoices(ChoiceSet): BLACK = 'dark' CHOICES = ( + (DEFAULT, 'Default'), (BLUE, 'Blue'), (GREY, 'Grey'), (GREEN, 'Green'),