Rename PluginNavMenuLink to PluginMenuItem

This commit is contained in:
Jeremy Stretch 2020-03-26 11:29:05 -04:00
parent 81c9177c09
commit 40574b65af
2 changed files with 8 additions and 8 deletions

View File

@ -281,14 +281,14 @@ With these three components in place, we can request `/api/plugins/animal-sounds
## Navigation Menu Items ## Navigation Menu Items
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 PluginNavMenuLink 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, PluginNavMenuLink from extras.plugins import PluginNavMenuButton, PluginMenuItem
from utilities.choices import ButtonColorChoices from utilities.choices import ButtonColorChoices
menu_items = ( menu_items = (
PluginNavMenuLink( PluginMenuItem(
link='plugins:netbox_animal_sounds:random_sound', link='plugins:netbox_animal_sounds:random_sound',
link_text='Random sound', link_text='Random sound',
buttons=( buttons=(
@ -299,7 +299,7 @@ menu_items = (
) )
``` ```
A `PluginNavMenuLink` has the following attributes: 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

View File

@ -152,7 +152,7 @@ def register_template_content_classes(class_list):
# Navigation menu links # Navigation menu links
# #
class PluginNavMenuLink: class PluginMenuItem:
""" """
This class represents a nav menu item. This constitutes primary link and its text, but also allows for This class represents a nav menu item. This constitutes primary link and its text, but also allows for
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.
@ -189,12 +189,12 @@ class PluginNavMenuButton:
def register_menu_items(section_name, class_list): def register_menu_items(section_name, class_list):
""" """
Register a list of PluginNavMenuLink instances for a given menu section (e.g. plugin name) Register a list of PluginMenuItem instances for a given menu section (e.g. plugin name)
""" """
# Validation # Validation
for menu_link in class_list: for menu_link in class_list:
if not isinstance(menu_link, PluginNavMenuLink): if not isinstance(menu_link, PluginMenuItem):
raise TypeError(f"{menu_link} must be an instance of extras.plugins.PluginNavMenuLink") 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, PluginNavMenuButton):
raise TypeError(f"{button} must be an instance of extras.plugins.PluginNavMenuButton") raise TypeError(f"{button} must be an instance of extras.plugins.PluginNavMenuButton")