mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Rename PluginNavMenuButton to PluginMenuButton
This commit is contained in:
@ -284,7 +284,7 @@ With these three components in place, we can request `/api/plugins/animal-sounds
|
|||||||
To make its views easily accessible to users, a plugin can inject items in NetBox's navigation menu under the "Plugins" header. Menu items are added by defining a list of PluginMenuItem instances. By default, this should be a variable named `menu_items` in the file `navigation.py`. An example is shown below.
|
To make its views easily accessible to users, a plugin can inject items in NetBox's navigation menu under the "Plugins" header. Menu items are added by defining a list of PluginMenuItem instances. By default, this should be a variable named `menu_items` in the file `navigation.py`. An example is shown below.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from extras.plugins import PluginNavMenuButton, PluginMenuItem
|
from extras.plugins import PluginMenuButton, PluginMenuItem
|
||||||
from utilities.choices import ButtonColorChoices
|
from utilities.choices import ButtonColorChoices
|
||||||
|
|
||||||
menu_items = (
|
menu_items = (
|
||||||
@ -292,8 +292,8 @@ menu_items = (
|
|||||||
link='plugins:netbox_animal_sounds:random_sound',
|
link='plugins:netbox_animal_sounds:random_sound',
|
||||||
link_text='Random sound',
|
link_text='Random sound',
|
||||||
buttons=(
|
buttons=(
|
||||||
PluginNavMenuButton('home', 'Button A', 'fa-info', ButtonColorChoices.BLUE),
|
PluginMenuButton('home', 'Button A', 'fa-info', ButtonColorChoices.BLUE),
|
||||||
PluginNavMenuButton('home', 'Button B', 'fa-warning', ButtonColorChoices.GREEN),
|
PluginMenuButton('home', 'Button B', 'fa-warning', ButtonColorChoices.GREEN),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -304,10 +304,10 @@ A `PluginMenuItem` has the following attributes:
|
|||||||
* `link` - The name of the URL path to which this menu item links
|
* `link` - The name of the URL path to which this menu item links
|
||||||
* `link_text` - The text presented to the user
|
* `link_text` - The text presented to the user
|
||||||
* `permission` - The name of the permission required to display this link (optional)
|
* `permission` - The name of the permission required to display this link (optional)
|
||||||
* `buttons` - An iterable of PluginNavMenuButton instances to display (optional)
|
* `buttons` - An iterable of PluginMenuButton instances to display (optional)
|
||||||
|
|
||||||
|
|
||||||
A `PluginNavMenuButton` has the following attributes:
|
A `PluginMenuButton` has the following attributes:
|
||||||
|
|
||||||
* `link` - The name of the URL path to which this button links
|
* `link` - The name of the URL path to which this button links
|
||||||
* `title` - The tooltip text (displayed when the mouse hovers over the button)
|
* `title` - The tooltip text (displayed when the mouse hovers over the button)
|
||||||
|
@ -158,7 +158,7 @@ class PluginMenuItem:
|
|||||||
specifying additional link buttons that appear to the right of the item in the van menu.
|
specifying additional link buttons that appear to the right of the item in the van menu.
|
||||||
|
|
||||||
Links are specified as Django reverse URL strings.
|
Links are specified as Django reverse URL strings.
|
||||||
Buttons are each specified as a list of PluginNavMenuButton instances.
|
Buttons are each specified as a list of PluginMenuButton instances.
|
||||||
"""
|
"""
|
||||||
def __init__(self, link, link_text, permission=None, buttons=None):
|
def __init__(self, link, link_text, permission=None, buttons=None):
|
||||||
self.link = link
|
self.link = link
|
||||||
@ -170,7 +170,7 @@ class PluginMenuItem:
|
|||||||
self.buttons = buttons
|
self.buttons = buttons
|
||||||
|
|
||||||
|
|
||||||
class PluginNavMenuButton:
|
class PluginMenuButton:
|
||||||
"""
|
"""
|
||||||
This class represents a button which is a part of the nav menu link item.
|
This class represents a button which is a part of the nav menu link item.
|
||||||
Note that button colors should come from ButtonColorChoices
|
Note that button colors should come from ButtonColorChoices
|
||||||
@ -196,7 +196,7 @@ def register_menu_items(section_name, class_list):
|
|||||||
if not isinstance(menu_link, PluginMenuItem):
|
if not isinstance(menu_link, PluginMenuItem):
|
||||||
raise TypeError(f"{menu_link} must be an instance of extras.plugins.PluginMenuItem")
|
raise TypeError(f"{menu_link} must be an instance of extras.plugins.PluginMenuItem")
|
||||||
for button in menu_link.buttons:
|
for button in menu_link.buttons:
|
||||||
if not isinstance(button, PluginNavMenuButton):
|
if not isinstance(button, PluginMenuButton):
|
||||||
raise TypeError(f"{button} must be an instance of extras.plugins.PluginNavMenuButton")
|
raise TypeError(f"{button} must be an instance of extras.plugins.PluginMenuButton")
|
||||||
|
|
||||||
registry['plugin_nav_menu_links'][section_name] = class_list
|
registry['plugin_nav_menu_links'][section_name] = class_list
|
||||||
|
Reference in New Issue
Block a user