Skip to content

Commit

Permalink
Merge pull request #10597 from netbox-community/9072-plugin-view-tabs
Browse files Browse the repository at this point in the history
#9072: Custom model view tabs for plugins
  • Loading branch information
jeremystretch committed Oct 7, 2022
2 parents 663652f + 053c97b commit a3dbf40
Show file tree
Hide file tree
Showing 33 changed files with 659 additions and 637 deletions.
26 changes: 26 additions & 0 deletions docs/plugins/development/views.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ These views are provided to enable or enhance certain NetBox model features, suc

## Extending Core Views

### Additional Tabs

Plugins can "attach" a custom view to a core NetBox model by registering it with `register_model_view()`. To include a tab for this view within the NetBox UI, declare a TabView instance named `tab`:

```python
from dcim.models import Site
from myplugin.models import Stuff
from netbox.views import generic
from utilities.views import ViewTab, register_model_view

@register_model_view(Site, 'mview', path='some-other-stuff')
class MyView(generic.ObjectView):
...
tab = ViewTab(
label='Other Stuff',
badge=lambda obj: Stuff.objects.filter(site=obj).count(),
permission='myplugin.view_stuff'
)
```

::: utilities.views.register_model_view

::: utilities.views.ViewTab

### Extra Template Content

Plugins can inject custom content into certain areas of the detail views of applicable models. This is accomplished by subclassing `PluginTemplateExtension`, designating a particular NetBox model, and defining the desired methods to render custom content. Four methods are available:

* `left_page()` - Inject content on the left side of the page
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes/version-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ A new `PluginMenu` class has been introduced, which enables a plugin to inject a
### Plugins API

* [#9071](https://github.com/netbox-community/netbox/issues/9071) - Introduce `PluginMenu` for top-level plugin navigation menus
* [#9072](https://github.com/netbox-community/netbox/issues/9072) - Enable registration of tabbed plugin views for core NetBox models
* [#9880](https://github.com/netbox-community/netbox/issues/9880) - Introduce `django_apps` plugin configuration parameter
* [#10314](https://github.com/netbox-community/netbox/issues/10314) - Move `clone()` method from NetBoxModel to CloningMixin

Expand Down
17 changes: 7 additions & 10 deletions netbox/circuits/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.urls import path
from django.urls import include, path

from dcim.views import PathTraceView
from netbox.views.generic import ObjectChangeLogView, ObjectJournalView
from utilities.urls import get_model_urls
from . import views
from .models import *
from .models import CircuitTermination

app_name = 'circuits'
urlpatterns = [
Expand All @@ -17,8 +17,7 @@
path('providers/<int:pk>/', views.ProviderView.as_view(), name='provider'),
path('providers/<int:pk>/edit/', views.ProviderEditView.as_view(), name='provider_edit'),
path('providers/<int:pk>/delete/', views.ProviderDeleteView.as_view(), name='provider_delete'),
path('providers/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='provider_changelog', kwargs={'model': Provider}),
path('providers/<int:pk>/journal/', ObjectJournalView.as_view(), name='provider_journal', kwargs={'model': Provider}),
path('providers/<int:pk>/', include(get_model_urls('circuits', 'provider'))),

# Provider networks
path('provider-networks/', views.ProviderNetworkListView.as_view(), name='providernetwork_list'),
Expand All @@ -29,8 +28,7 @@
path('provider-networks/<int:pk>/', views.ProviderNetworkView.as_view(), name='providernetwork'),
path('provider-networks/<int:pk>/edit/', views.ProviderNetworkEditView.as_view(), name='providernetwork_edit'),
path('provider-networks/<int:pk>/delete/', views.ProviderNetworkDeleteView.as_view(), name='providernetwork_delete'),
path('provider-networks/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='providernetwork_changelog', kwargs={'model': ProviderNetwork}),
path('provider-networks/<int:pk>/journal/', ObjectJournalView.as_view(), name='providernetwork_journal', kwargs={'model': ProviderNetwork}),
path('provider-networks/<int:pk>/', include(get_model_urls('circuits', 'providernetwork'))),

# Circuit types
path('circuit-types/', views.CircuitTypeListView.as_view(), name='circuittype_list'),
Expand All @@ -41,7 +39,7 @@
path('circuit-types/<int:pk>/', views.CircuitTypeView.as_view(), name='circuittype'),
path('circuit-types/<int:pk>/edit/', views.CircuitTypeEditView.as_view(), name='circuittype_edit'),
path('circuit-types/<int:pk>/delete/', views.CircuitTypeDeleteView.as_view(), name='circuittype_delete'),
path('circuit-types/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='circuittype_changelog', kwargs={'model': CircuitType}),
path('circuit-types/<int:pk>/', include(get_model_urls('circuits', 'circuittype'))),

# Circuits
path('circuits/', views.CircuitListView.as_view(), name='circuit_list'),
Expand All @@ -52,9 +50,8 @@
path('circuits/<int:pk>/', views.CircuitView.as_view(), name='circuit'),
path('circuits/<int:pk>/edit/', views.CircuitEditView.as_view(), name='circuit_edit'),
path('circuits/<int:pk>/delete/', views.CircuitDeleteView.as_view(), name='circuit_delete'),
path('circuits/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='circuit_changelog', kwargs={'model': Circuit}),
path('circuits/<int:pk>/journal/', ObjectJournalView.as_view(), name='circuit_journal', kwargs={'model': Circuit}),
path('circuits/<int:pk>/terminations/swap/', views.CircuitSwapTerminations.as_view(), name='circuit_terminations_swap'),
path('circuits/<int:pk>/', include(get_model_urls('circuits', 'circuit'))),

# Circuit terminations
path('circuit-terminations/add/', views.CircuitTerminationEditView.as_view(), name='circuittermination_add'),
Expand Down
Loading

0 comments on commit a3dbf40

Please sign in to comment.