-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jasonyates/develop
NB 3.4 Updates
- Loading branch information
Showing
5 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,85 @@ | ||
from extras.plugins import PluginMenuItem | ||
from extras.plugins import PluginMenuItem, PluginMenu, PluginMenuButton | ||
from utilities.choices import ButtonColorChoices | ||
from django.conf import settings | ||
|
||
plugin_settings = settings.PLUGINS_CONFIG.get('netbox_documents', {}) | ||
|
||
if plugin_settings.get('enable_navigation_menu'): | ||
|
||
menu_items = [] | ||
menuitem = [] | ||
|
||
# Add a menu item for Site Documents if enabled | ||
if plugin_settings.get('enable_site_documents'): | ||
menu_items.append(PluginMenuItem( | ||
link='plugins:netbox_documents:sitedocument_list', | ||
link_text='Site Documents' | ||
)) | ||
menuitem.append( | ||
PluginMenuItem( | ||
link='plugins:netbox_documents:sitedocument_list', | ||
link_text='Site Documents', | ||
buttons=[PluginMenuButton( | ||
link='plugins:netbox_documents:sitedocument_add', | ||
title='Add', | ||
icon_class='mdi mdi-plus-thick', | ||
color=ButtonColorChoices.GREEN | ||
)] | ||
) | ||
) | ||
|
||
# Add a menu item for Device Documents if enabled | ||
if plugin_settings.get('enable_device_documents'): | ||
menu_items.append( | ||
menuitem.append( | ||
PluginMenuItem( | ||
link='plugins:netbox_documents:devicedocument_list', | ||
link_text='Device Documents' | ||
link_text='Device Documents', | ||
buttons=[PluginMenuButton( | ||
link='plugins:netbox_documents:devicedocument_add', | ||
title='Add', | ||
icon_class='mdi mdi-plus-thick', | ||
color=ButtonColorChoices.GREEN | ||
)] | ||
) | ||
) | ||
|
||
|
||
# Add a menu item for Device Documents if enabled | ||
if plugin_settings.get('enable_device_type_documents'): | ||
menu_items.append( | ||
menuitem.append( | ||
PluginMenuItem( | ||
link='plugins:netbox_documents:devicetypedocument_list', | ||
link_text='Device Type Documents' | ||
link_text='Device Type Documents', | ||
buttons=[PluginMenuButton( | ||
link='plugins:netbox_documents:devicetypedocument_add', | ||
title='Add', | ||
icon_class='mdi mdi-plus-thick', | ||
color=ButtonColorChoices.GREEN | ||
)] | ||
) | ||
) | ||
|
||
# Add a menu item for Circuit Documents if enabled | ||
if plugin_settings.get('enable_circuit_documents'): | ||
menu_items.append( | ||
menuitem.append( | ||
PluginMenuItem( | ||
link='plugins:netbox_documents:circuitdocument_list', | ||
link_text='Circuit Documents' | ||
link_text='Circuit Documents', | ||
buttons=[PluginMenuButton( | ||
link='plugins:netbox_documents:circuitdocument_add', | ||
title='Add', | ||
icon_class='mdi mdi-plus-thick', | ||
color=ButtonColorChoices.GREEN | ||
)] | ||
) | ||
) | ||
) | ||
|
||
# If we are using NB 3.4.0+ display the new top level navigation option | ||
if settings.VERSION >= '3.4.0': | ||
|
||
menu = PluginMenu( | ||
label='Documents', | ||
groups=( | ||
('Document Storage', menuitem), | ||
), | ||
icon_class='mdi mdi-file-document-multiple' | ||
) | ||
|
||
else: | ||
|
||
# Fall back to pre 3.4 navigation option | ||
menu_items = menuitem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from netbox.search import SearchIndex | ||
from .models import SiteDocument, DeviceDocument, DeviceTypeDocument, CircuitDocument | ||
from django.conf import settings | ||
|
||
# If we run NB 3.4+ register search indexes | ||
if settings.VERSION >= '3.4.0': | ||
class SiteDocumentIndex(SearchIndex): | ||
model = SiteDocument | ||
fields = ( | ||
("name", 100), | ||
("document", 500), | ||
("comments", 5000), | ||
) | ||
|
||
class CircuitDocumentIndex(SearchIndex): | ||
model = CircuitDocument | ||
fields = ( | ||
("name", 100), | ||
("document", 500), | ||
("comments", 5000), | ||
) | ||
|
||
class DeviceTypeDocumentIndex(SearchIndex): | ||
model = DeviceTypeDocument | ||
fields = ( | ||
("name", 100), | ||
("document", 500), | ||
("comments", 5000), | ||
) | ||
|
||
class DeviceDocumentIndex(SearchIndex): | ||
model = DeviceDocument | ||
fields = ( | ||
("name", 100), | ||
("document", 500), | ||
("comments", 5000), | ||
) | ||
|
||
# Register indexes | ||
indexes = [SiteDocumentIndex, CircuitDocumentIndex, DeviceTypeDocumentIndex, DeviceDocumentIndex] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters