mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Closes #4956: Include inventory items on primary device view
This commit is contained in:
parent
52dc80209c
commit
584b076886
@ -7,6 +7,7 @@
|
|||||||
### New Features
|
### New Features
|
||||||
|
|
||||||
* [#1692](https://github.com/netbox-community/netbox/issues/1692) - Allow assigment of inventory items to parent items in web UI
|
* [#1692](https://github.com/netbox-community/netbox/issues/1692) - Allow assigment of inventory items to parent items in web UI
|
||||||
|
* [#4956](https://github.com/netbox-community/netbox/issues/4956) - Include inventory items on primary device view
|
||||||
* [#5146](https://github.com/netbox-community/netbox/issues/5146) - Add custom fields support for cables, power panels, rack reservations, and virtual chassis
|
* [#5146](https://github.com/netbox-community/netbox/issues/5146) - Add custom fields support for cables, power panels, rack reservations, and virtual chassis
|
||||||
|
|
||||||
### Other Changes
|
### Other Changes
|
||||||
|
@ -189,7 +189,6 @@ urlpatterns = [
|
|||||||
path('devices/<int:pk>/delete/', views.DeviceDeleteView.as_view(), name='device_delete'),
|
path('devices/<int:pk>/delete/', views.DeviceDeleteView.as_view(), name='device_delete'),
|
||||||
path('devices/<int:pk>/config-context/', views.DeviceConfigContextView.as_view(), name='device_configcontext'),
|
path('devices/<int:pk>/config-context/', views.DeviceConfigContextView.as_view(), name='device_configcontext'),
|
||||||
path('devices/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='device_changelog', kwargs={'model': Device}),
|
path('devices/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='device_changelog', kwargs={'model': Device}),
|
||||||
path('devices/<int:pk>/inventory/', views.DeviceInventoryView.as_view(), name='device_inventory'),
|
|
||||||
path('devices/<int:pk>/status/', views.DeviceStatusView.as_view(), name='device_status'),
|
path('devices/<int:pk>/status/', views.DeviceStatusView.as_view(), name='device_status'),
|
||||||
path('devices/<int:pk>/lldp-neighbors/', views.DeviceLLDPNeighborsView.as_view(), name='device_lldp_neighbors'),
|
path('devices/<int:pk>/lldp-neighbors/', views.DeviceLLDPNeighborsView.as_view(), name='device_lldp_neighbors'),
|
||||||
path('devices/<int:pk>/config/', views.DeviceConfigView.as_view(), name='device_config'),
|
path('devices/<int:pk>/config/', views.DeviceConfigView.as_view(), name='device_config'),
|
||||||
|
@ -1050,6 +1050,11 @@ class DeviceView(ObjectView):
|
|||||||
'installed_device__device_type__manufacturer',
|
'installed_device__device_type__manufacturer',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Inventory items
|
||||||
|
inventoryitems = InventoryItem.objects.restrict(request.user, 'view').filter(
|
||||||
|
device=device
|
||||||
|
).prefetch_related('manufacturer')
|
||||||
|
|
||||||
# Services
|
# Services
|
||||||
services = Service.objects.restrict(request.user, 'view').filter(device=device)
|
services = Service.objects.restrict(request.user, 'view').filter(device=device)
|
||||||
|
|
||||||
@ -1072,9 +1077,10 @@ class DeviceView(ObjectView):
|
|||||||
'powerports': powerports,
|
'powerports': powerports,
|
||||||
'poweroutlets': poweroutlets,
|
'poweroutlets': poweroutlets,
|
||||||
'interfaces': interfaces,
|
'interfaces': interfaces,
|
||||||
'devicebays': devicebays,
|
|
||||||
'frontports': frontports,
|
'frontports': frontports,
|
||||||
'rearports': rearports,
|
'rearports': rearports,
|
||||||
|
'devicebays': devicebays,
|
||||||
|
'inventoryitems': inventoryitems,
|
||||||
'services': services,
|
'services': services,
|
||||||
'secrets': secrets,
|
'secrets': secrets,
|
||||||
'vc_members': vc_members,
|
'vc_members': vc_members,
|
||||||
@ -1082,23 +1088,6 @@ class DeviceView(ObjectView):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class DeviceInventoryView(ObjectView):
|
|
||||||
queryset = Device.objects.all()
|
|
||||||
|
|
||||||
def get(self, request, pk):
|
|
||||||
|
|
||||||
device = get_object_or_404(self.queryset, pk=pk)
|
|
||||||
inventory_items = InventoryItem.objects.restrict(request.user, 'view').filter(
|
|
||||||
device=device
|
|
||||||
).prefetch_related('manufacturer')
|
|
||||||
|
|
||||||
return render(request, 'dcim/device_inventory.html', {
|
|
||||||
'device': device,
|
|
||||||
'inventory_items': inventory_items,
|
|
||||||
'active_tab': 'inventory',
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceStatusView(ObjectView):
|
class DeviceStatusView(ObjectView):
|
||||||
additional_permissions = ['dcim.napalm_read_device']
|
additional_permissions = ['dcim.napalm_read_device']
|
||||||
queryset = Device.objects.all()
|
queryset = Device.objects.all()
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
<li><a href="{% url 'dcim:devicebay_add' %}?device={{ device.pk }}&return_url={{ device.get_absolute_url }}">Device Bays</a></li>
|
<li><a href="{% url 'dcim:devicebay_add' %}?device={{ device.pk }}&return_url={{ device.get_absolute_url }}">Device Bays</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if perms.dcim.add_inventoryitem %}
|
{% if perms.dcim.add_inventoryitem %}
|
||||||
<li><a href="{% url 'dcim:inventoryitem_add' %}?device={{ device.pk }}&return_url={% url 'dcim:device_inventory' pk=device.pk %}">Inventory Items</a></li>
|
<li><a href="{% url 'dcim:inventoryitem_add' %}?device={{ device.pk }}&return_url={{ device.get_absolute_url }}">Inventory Items</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -93,11 +93,6 @@
|
|||||||
<li role="presentation"{% if not active_tab %} class="active"{% endif %}>
|
<li role="presentation"{% if not active_tab %} class="active"{% endif %}>
|
||||||
<a href="{% url 'dcim:device' pk=device.pk %}">Device</a>
|
<a href="{% url 'dcim:device' pk=device.pk %}">Device</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation"{% if active_tab == 'inventory' %} class="active"{% endif %}>
|
|
||||||
<a href="{% url 'dcim:device_inventory' pk=device.pk %}">
|
|
||||||
Inventory <span class="badge">{{ device.inventoryitems.unrestricted.count }}</span>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
{% if perms.dcim.napalm_read_device %}
|
{% if perms.dcim.napalm_read_device %}
|
||||||
{% if device.status != 'active' %}
|
{% if device.status != 'active' %}
|
||||||
{% include 'dcim/inc/device_napalm_tabs.html' with disabled_message='Device must be in active status' %}
|
{% include 'dcim/inc/device_napalm_tabs.html' with disabled_message='Device must be in active status' %}
|
||||||
@ -123,6 +118,42 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<ul class="nav nav-pills" role="tablist">
|
||||||
|
<li role="presentation" class="active">
|
||||||
|
<a href="#details" role="tab" data-toggle="tab">Details</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#interfaces" role="tab" data-toggle="tab">Interfaces {% badge interfaces|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#frontports" role="tab" data-toggle="tab">Front Ports {% badge frontports|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#rearports" role="tab" data-toggle="tab">Rear Ports {% badge rearports|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleports|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#consoleserverports" role="tab" data-toggle="tab">Console Server Ports {% badge consoleserverports|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerports|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlets|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#devicebays" role="tab" data-toggle="tab">Device Bays {% badge devicebays|length %}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="#inventoryitems" role="tab" data-toggle="tab">Inventory {% badge inventoryitems|length %}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<div role="tabpanel" class="tab-pane active" id="details">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
@ -464,35 +495,7 @@
|
|||||||
{% plugin_full_width_page device %}
|
{% plugin_full_width_page device %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
</div>
|
||||||
<div class="col-md-12">
|
|
||||||
<ul class="nav nav-tabs" role="tablist">
|
|
||||||
<li role="presentation" class="active">
|
|
||||||
<a href="#interfaces" role="tab" data-toggle="tab">Interfaces {% badge interfaces|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#frontports" role="tab" data-toggle="tab">Front Ports {% badge frontports|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#rearports" role="tab" data-toggle="tab">Rear Ports {% badge rearports|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleports|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#consoleserverports" role="tab" data-toggle="tab">Console Server Ports {% badge consoleserverports|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#powerports" role="tab" data-toggle="tab">Power Ports {% badge powerports|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#poweroutlets" role="tab" data-toggle="tab">Power Outlets {% badge poweroutlets|length %}</a>
|
|
||||||
</li>
|
|
||||||
<li role="presentation">
|
|
||||||
<a href="#devicebays" role="tab" data-toggle="tab">Device Bays {% badge devicebays|length %}</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<div class="tab-content">
|
|
||||||
<div role="tabpanel" class="tab-pane active" id="interfaces">
|
<div role="tabpanel" class="tab-pane active" id="interfaces">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
@ -949,6 +952,60 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div role="tabpanel" class="tab-pane" id="inventoryitems">
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<strong>Inventory Items</strong>
|
||||||
|
</div>
|
||||||
|
<table class="table table-hover table-condensed panel-body" id="hardware">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{% if perms.dcim.change_inventoryitem or perms.dcim.delete_inventoryitem %}
|
||||||
|
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
||||||
|
{% endif %}
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Manufacturer</th>
|
||||||
|
<th>Part ID</th>
|
||||||
|
<th>Serial Number</th>
|
||||||
|
<th>Asset Tag</th>
|
||||||
|
<th>Discovered</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for item in inventoryitems %}
|
||||||
|
{% include 'dcim/inc/inventoryitem.html' %}
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="panel-footer noprint">
|
||||||
|
{% if inventoryitems and perms.dcim.change_inventoryitem %}
|
||||||
|
<button type="submit" name="_rename" formaction="{% url 'dcim:inventoryitem_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
||||||
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
||||||
|
</button>
|
||||||
|
<button type="submit" name="_edit" formaction="{% url 'dcim:inventoryitem_bulk_edit' %}?device={{ device.pk }}&return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
||||||
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% if inventoryitems and perms.dcim.delete_inventoryitem %}
|
||||||
|
<button type="submit" name="_delete" formaction="{% url 'dcim:inventoryitem_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
||||||
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
{% if perms.dcim.add_inventoryitem %}
|
||||||
|
<div class="pull-right">
|
||||||
|
<a href="{% url 'dcim:inventoryitem_add' %}?device={{ device.pk }}&return_url={{ device.get_absolute_url }}" class="btn btn-primary btn-xs">
|
||||||
|
<span class="fa fa-plus" aria-hidden="true"></span> Add Inventory Item
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
{% extends 'dcim/device.html' %}
|
|
||||||
{% load helpers %}
|
|
||||||
|
|
||||||
{% block title %}{{ device }} - Inventory{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-12">
|
|
||||||
<form method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<strong>Inventory Items</strong>
|
|
||||||
</div>
|
|
||||||
<table class="table table-hover table-condensed panel-body" id="hardware">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
{% if perms.dcim.change_inventoryitem or perms.dcim.delete_inventoryitem %}
|
|
||||||
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
|
||||||
{% endif %}
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Manufacturer</th>
|
|
||||||
<th>Part ID</th>
|
|
||||||
<th>Serial Number</th>
|
|
||||||
<th>Asset Tag</th>
|
|
||||||
<th>Discovered</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for item in inventory_items %}
|
|
||||||
{% include 'dcim/inc/inventoryitem.html' %}
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="panel-footer noprint">
|
|
||||||
{% if inventory_items and perms.dcim.change_inventoryitem %}
|
|
||||||
<button type="submit" name="_rename" formaction="{% url 'dcim:inventoryitem_bulk_rename' %}?return_url={% url 'dcim:device_inventory' pk=device.pk %}" class="btn btn-warning btn-xs">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
|
||||||
</button>
|
|
||||||
<button type="submit" name="_edit" formaction="{% url 'dcim:inventoryitem_bulk_edit' %}?device={{ device.pk }}&return_url={% url 'dcim:device_inventory' pk=device.pk %}" class="btn btn-warning btn-xs">
|
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
{% if inventory_items and perms.dcim.delete_inventoryitem %}
|
|
||||||
<button type="submit" name="_delete" formaction="{% url 'dcim:inventoryitem_bulk_delete' %}?return_url={% url 'dcim:device_inventory' pk=device.pk %}" class="btn btn-danger btn-xs">
|
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
|
||||||
</button>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.dcim.add_inventoryitem %}
|
|
||||||
<div class="pull-right">
|
|
||||||
<a href="{% url 'dcim:inventoryitem_add' %}?device={{ device.pk }}&return_url={% url 'dcim:device_inventory' pk=device.pk %}" class="btn btn-primary btn-xs">
|
|
||||||
<span class="fa fa-plus" aria-hidden="true"></span> Add Inventory Item
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
@ -31,10 +31,10 @@
|
|||||||
<td>{{ item.description|placeholder }}</td>
|
<td>{{ item.description|placeholder }}</td>
|
||||||
<td class="text-right noprint">
|
<td class="text-right noprint">
|
||||||
{% if perms.dcim.change_inventoryitem %}
|
{% if perms.dcim.change_inventoryitem %}
|
||||||
<a href="{% url 'dcim:inventoryitem_edit' pk=item.pk %}?return_url={% url 'dcim:device_inventory' pk=device.pk %}" class="btn btn-xs btn-warning"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
|
<a href="{% url 'dcim:inventoryitem_edit' pk=item.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-xs btn-warning"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if perms.dcim.delete_inventoryitem %}
|
{% if perms.dcim.delete_inventoryitem %}
|
||||||
<a href="{% url 'dcim:inventoryitem_delete' pk=item.pk %}?return_url={% url 'dcim:device_inventory' pk=device.pk %}" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
<a href="{% url 'dcim:inventoryitem_delete' pk=item.pk %}?return_url={{ device.get_absolute_url }}" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
Reference in New Issue
Block a user