Skip to content

Commit

Permalink
Merge pull request #214 from ArnesSI/nb42
Browse files Browse the repository at this point in the history
netbox 4.2 changes
  • Loading branch information
matejv authored Jan 15, 2025
2 parents cdf54a4 + 1494eaf commit 2986fd4
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
fail-fast: false
matrix:
netbox-version: ["v4.1.8", "v4.2.1"]
netbox-version: ["v4.2.1"]
services:
redis:
image: redis
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ support older netbox version as per table below:
| 3.7 | 1.6.x |
| 4.0 | 2.0.x |
| 4.1 | 2.1.x,2.2.x |
| 4.2 | 2.3.x |

## Installing

Expand Down
2 changes: 1 addition & 1 deletion netbox_inventory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NetBoxInventoryConfig(PluginConfig):
author = 'Matej Vadnjal'
author_email = '[email protected]'
base_url = 'inventory'
min_version = '4.1.0'
min_version = '4.2.1'
default_settings = {
'top_level_menu': True,
'used_status_name': 'used',
Expand Down
12 changes: 6 additions & 6 deletions netbox_inventory/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
permissions=["netbox_inventory.add_asset"],
),
PluginMenuButton(
link='plugins:netbox_inventory:asset_import',
link='plugins:netbox_inventory:asset_bulk_import',
title='Import',
icon_class='mdi mdi-upload',
permissions=["netbox_inventory.add_asset"],
Expand All @@ -24,7 +24,7 @@
permissions=["netbox_inventory.add_supplier"],
),
PluginMenuButton(
link='plugins:netbox_inventory:supplier_import',
link='plugins:netbox_inventory:supplier_bulk_import',
title='Import',
icon_class='mdi mdi-upload',
permissions=["netbox_inventory.add_supplier"],
Expand All @@ -39,7 +39,7 @@
permissions=["netbox_inventory.add_purchase"],
),
PluginMenuButton(
link='plugins:netbox_inventory:purchase_import',
link='plugins:netbox_inventory:purchase_bulk_import',
title='Import',
icon_class='mdi mdi-upload',
permissions=["netbox_inventory.add_purchase"],
Expand All @@ -54,7 +54,7 @@
permissions=["netbox_inventory.add_delivery"],
),
PluginMenuButton(
link='plugins:netbox_inventory:delivery_import',
link='plugins:netbox_inventory:delivery_bulk_import',
title='Import',
icon_class='mdi mdi-upload',
permissions=["netbox_inventory.add_delivery"],
Expand All @@ -69,7 +69,7 @@
permissions=["netbox_inventory.add_inventoryitemtype"],
),
PluginMenuButton(
link='plugins:netbox_inventory:inventoryitemtype_import',
link='plugins:netbox_inventory:inventoryitemtype_bulk_import',
title='Import',
icon_class='mdi mdi-upload',
permissions=["netbox_inventory.add_inventoryitemtype"],
Expand All @@ -84,7 +84,7 @@
permissions=["netbox_inventory.add_inventoryitemgroup"],
),
PluginMenuButton(
link='plugins:netbox_inventory:inventoryitemgroup_import',
link='plugins:netbox_inventory:inventoryitemgroup_bulk_import',
title='Import',
icon_class='mdi mdi-upload',
permissions=["netbox_inventory.add_inventoryitemgroup"],
Expand Down
20 changes: 10 additions & 10 deletions netbox_inventory/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,27 @@ def right_page(self):


class DeviceAssetInfo(AssetInfoExtension):
model = 'dcim.device'
models = ['dcim.device']
kind = 'device'


class ModuleAssetInfo(AssetInfoExtension):
model = 'dcim.module'
models = ['dcim.module']
kind = 'module'


class InventoryItemAssetInfo(AssetInfoExtension):
model = 'dcim.inventoryitem'
models = ['dcim.inventoryitem']
kind = 'inventoryitem'


class RackAssetInfo(AssetInfoExtension):
model = 'dcim.rack'
models = ['dcim.rack']
kind = 'rack'


class ManufacturerAssetCounts(PluginTemplateExtension):
model = 'dcim.manufacturer'
models = ['dcim.manufacturer']
def right_page(self):
object = self.context.get('object')
user = self.context['request'].user
Expand Down Expand Up @@ -151,18 +151,18 @@ def right_page(self):


class SiteAssetCounts(AssetLocationCounts):
model = 'dcim.site'
models = ['dcim.site']
location_type='site'


class LocationAssetCounts(AssetLocationCounts):
model = 'dcim.location'
models = ['dcim.location']
location_type='location'


class RackAssetCounts(PluginTemplateExtension):
# rack cannot have stored assets so we can't use AssetLocationStats
model = 'dcim.rack'
models = ['dcim.rack']
def right_page(self):
object = self.context.get('object')
user = self.context['request'].user
Expand All @@ -181,7 +181,7 @@ def right_page(self):


class TenantAssetCounts(PluginTemplateExtension):
model = 'tenancy.tenant'
models = ['tenancy.tenant']
def right_page(self):
object = self.context.get('object')
user = self.context['request'].user
Expand All @@ -203,7 +203,7 @@ def right_page(self):


class ContactAssetCounts(PluginTemplateExtension):
model = 'tenancy.contact'
models = ['tenancy.contact']
def right_page(self):
object = self.context.get('object')
user = self.context['request'].user
Expand Down
1 change: 1 addition & 0 deletions netbox_inventory/templates/netbox_inventory/supplier.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ <h5 class="card-header">Supplied Assets</h5>
</div>
{% plugin_full_width_page object %}
</div>
</div>
{% endblock content %}
2 changes: 2 additions & 0 deletions netbox_inventory/tests/asset/test_views_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def setUp(self):
self.form_data = {
'device': self.device1.pk,
'name': 'inventoryitem1',
'status': 'active',
}
self.tested_asset = self.asset_inventoryitem_sn

Expand Down Expand Up @@ -248,6 +249,7 @@ def setUp(self):
self.form_data = {
'device': self.device1.pk,
'name': 'inventoryitem1',
'status': 'active',
}
self.tested_asset = self.asset_inventoryitem_no

Expand Down
2 changes: 1 addition & 1 deletion netbox_inventory/tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NetboxInventoryVersionTestCase(SimpleTestCase):
"""

def test_version(self):
assert __version__ == "2.2.1"
assert __version__ == "2.3.0"


class AppTest(APITestCase):
Expand Down
69 changes: 12 additions & 57 deletions netbox_inventory/urls.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
from django.urls import include, path

from netbox.views.generic import ObjectChangeLogView, ObjectJournalView
from utilities.urls import get_model_urls
from . import models, views
from . import views


urlpatterns = (

# Assets
path('assets/', views.AssetListView.as_view(), name='asset_list'),
path('assets/add/', views.AssetEditView.as_view(), name='asset_add'),
path('assets/bulk-add/', views.AssetBulkCreateView.as_view(), name='asset_bulk_add'),
path('assets/import/', views.AssetBulkImportView.as_view(), name='asset_import'),
path('assets/edit/', views.AssetBulkEditView.as_view(), name='asset_bulk_edit'),
path('assets/delete/', views.AssetBulkDeleteView.as_view(), name='asset_bulk_delete'),
path('assets/<int:pk>', views.AssetView.as_view(), name='asset'),
path('assets/<int:pk>/edit/', views.AssetEditView.as_view(), name='asset_edit'),
path('assets/<int:pk>/delete/', views.AssetDeleteView.as_view(), name='asset_delete'),
path('assets/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='asset_changelog', kwargs={'model': models.Asset}),
path('assets/<int:pk>/journal/', ObjectJournalView.as_view(), name='asset_journal', kwargs={'model': models.Asset}),
path('assets/', include(get_model_urls('netbox_inventory', 'asset', detail=False))),
path('assets/<int:pk>/', include(get_model_urls('netbox_inventory', 'asset'))),
path('assets/<int:pk>/assign/', views.AssetAssignView.as_view(), name='asset_assign'),
path('assets/device/create/', views.AssetDeviceCreateView.as_view(), name='asset_device_create'),
path('assets/module/create/', views.AssetModuleCreateView.as_view(), name='asset_module_create'),
Expand All @@ -30,58 +20,23 @@
path('assets/rack/<int:pk>/reassign/', views.AssetRackReassignView.as_view(), name='asset_rack_reassign'),

# Suppliers
path('suppliers/', views.SupplierListView.as_view(), name='supplier_list'),
path('suppliers/add/', views.SupplierEditView.as_view(), name='supplier_add'),
path('suppliers/import/', views.SupplierBulkImportView.as_view(), name='supplier_import'),
path('suppliers/edit/', views.SupplierBulkEditView.as_view(), name='supplier_bulk_edit'),
path('suppliers/delete/', views.SupplierBulkDeleteView.as_view(), name='supplier_bulk_delete'),
path('suppliers/<int:pk>', views.SupplierView.as_view(), name='supplier'),
path('suppliers/', include(get_model_urls('netbox_inventory', 'supplier', detail=False))),
path('suppliers/<int:pk>/', include(get_model_urls('netbox_inventory', 'supplier'))),

# Purchases
path('purchases/', views.PurchaseListView.as_view(), name='purchase_list'),
path('purchases/add/', views.PurchaseEditView.as_view(), name='purchase_add'),
path('purchases/import/', views.PurchaseBulkImportView.as_view(), name='purchase_import'),
path('purchases/edit/', views.PurchaseBulkEditView.as_view(), name='purchase_bulk_edit'),
path('purchases/delete/', views.PurchaseBulkDeleteView.as_view(), name='purchase_bulk_delete'),
path('purchases/<int:pk>', views.PurchaseView.as_view(), name='purchase'),
path('purchases/<int:pk>/edit/', views.PurchaseEditView.as_view(), name='purchase_edit'),
path('purchases/<int:pk>/delete/', views.PurchaseDeleteView.as_view(), name='purchase_delete'),
path('purchases/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='purchase_changelog', kwargs={'model': models.Purchase}),
path('purchases/<int:pk>/journal/', ObjectJournalView.as_view(), name='purchase_journal', kwargs={'model': models.Purchase}),
path('purchases/', include(get_model_urls('netbox_inventory', 'purchase', detail=False))),
path('purchases/<int:pk>/', include(get_model_urls('netbox_inventory', 'purchase'))),

# Deliveries
path('deliveries/', views.DeliveryListView.as_view(), name='delivery_list'),
path('deliveries/add/', views.DeliveryEditView.as_view(), name='delivery_add'),
path('deliveries/import/', views.DeliveryBulkImportView.as_view(), name='delivery_import'),
path('deliveries/edit/', views.DeliveryBulkEditView.as_view(), name='delivery_bulk_edit'),
path('deliveries/delete/', views.DeliveryBulkDeleteView.as_view(), name='delivery_bulk_delete'),
path('deliveries/<int:pk>', views.DeliveryView.as_view(), name='delivery'),
path('deliveries/<int:pk>/edit/', views.DeliveryEditView.as_view(), name='delivery_edit'),
path('deliveries/<int:pk>/delete/', views.DeliveryDeleteView.as_view(), name='delivery_delete'),
path('deliveries/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='delivery_changelog', kwargs={'model': models.Delivery}),
path('deliveries/<int:pk>/journal/', ObjectJournalView.as_view(), name='delivery_journal', kwargs={'model': models.Delivery}),
path('deliveries/', include(get_model_urls('netbox_inventory', 'delivery', detail=False))),
path('deliveries/<int:pk>/', include(get_model_urls('netbox_inventory', 'delivery'))),

# InventoryItemTypes
path('inventory-item-types/', views.InventoryItemTypeListView.as_view(), name='inventoryitemtype_list'),
path('inventory-item-types/add/', views.InventoryItemTypeEditView.as_view(), name='inventoryitemtype_add'),
path('inventory-item-types/import/', views.InventoryItemTypeBulkImportView.as_view(), name='inventoryitemtype_import'),
path('inventory-item-types/edit/', views.InventoryItemTypeBulkEditView.as_view(), name='inventoryitemtype_bulk_edit'),
path('inventory-item-types/delete/', views.InventoryItemTypeBulkDeleteView.as_view(), name='inventoryitemtype_bulk_delete'),
path('inventory-item-types/<int:pk>', views.InventoryItemTypeView.as_view(), name='inventoryitemtype'),
path('inventory-item-types/<int:pk>/edit/', views.InventoryItemTypeEditView.as_view(), name='inventoryitemtype_edit'),
path('inventory-item-types/<int:pk>/delete/', views.InventoryItemTypeDeleteView.as_view(), name='inventoryitemtype_delete'),
path('inventory-item-types/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='inventoryitemtype_changelog', kwargs={'model': models.InventoryItemType}),
path('inventory-item-types/', include(get_model_urls('netbox_inventory', 'inventoryitemtype', detail=False))),
path('inventory-item-types/<int:pk>/', include(get_model_urls('netbox_inventory', 'inventoryitemtype'))),

# InventoryItemGroups
path('inventory-item-groups/', views.InventoryItemGroupListView.as_view(), name='inventoryitemgroup_list'),
path('inventory-item-groups/add/', views.InventoryItemGroupEditView.as_view(), name='inventoryitemgroup_add'),
path('inventory-item-groups/import/', views.InventoryItemGroupBulkImportView.as_view(), name='inventoryitemgroup_import'),
path('inventory-item-groups/edit/', views.InventoryItemGroupBulkEditView.as_view(), name='inventoryitemgroup_bulk_edit'),
path('inventory-item-groups/delete/', views.InventoryItemGroupBulkDeleteView.as_view(), name='inventoryitemgroup_bulk_delete'),
path('inventory-item-groups/<int:pk>', views.InventoryItemGroupView.as_view(), name='inventoryitemgroup'),
path('inventory-item-groups/<int:pk>/edit/', views.InventoryItemGroupEditView.as_view(), name='inventoryitemgroup_edit'),
path('inventory-item-groups/<int:pk>/delete/', views.InventoryItemGroupDeleteView.as_view(), name='inventoryitemgroup_delete'),
path('inventory-item-groups/<int:pk>/changelog/', ObjectChangeLogView.as_view(), name='inventoryitemgroup_changelog', kwargs={'model': models.InventoryItemGroup}),
path('inventory-item-groups/', include(get_model_urls('netbox_inventory', 'inventoryitemgroup', detail=False))),
path('inventory-item-groups/<int:pk>/', include(get_model_urls('netbox_inventory', 'inventoryitemgroup'))),

)
2 changes: 1 addition & 1 deletion netbox_inventory/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.2.1'
__version__ = '2.3.0'
10 changes: 10 additions & 0 deletions netbox_inventory/views/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.template import Template
from netbox.views import generic
from utilities.forms import ConfirmationForm, restrict_form_fields
from utilities.views import register_model_view

from .. import filtersets, forms, models, tables
from ..template_content import WARRANTY_PROGRESSBAR
Expand All @@ -26,6 +27,7 @@
)


@register_model_view(models.Asset)
class AssetView(generic.ObjectView):
queryset = models.Asset.objects.all()

Expand All @@ -35,6 +37,7 @@ def get_extra_context(self, request, instance):
return context


@register_model_view(models.Asset, 'list', path='', detail=False)
class AssetListView(generic.ObjectListView):
queryset = models.Asset.objects.prefetch_related(
'device_type__manufacturer',
Expand All @@ -56,6 +59,7 @@ class AssetListView(generic.ObjectListView):
filterset_form = forms.AssetFilterForm


@register_model_view(models.Asset, 'bulk_add', path='bulk-add', detail=False)
class AssetBulkCreateView(generic.BulkCreateView):
queryset = models.Asset.objects.all()
form = forms.AssetBulkAddForm
Expand All @@ -82,12 +86,15 @@ def _create_objects(self, form, request):
return new_objects


@register_model_view(models.Asset, 'edit')
@register_model_view(models.Asset, 'add', detail=False)
class AssetEditView(generic.ObjectEditView):
queryset = models.Asset.objects.all()
form = forms.AssetForm
template_name = 'netbox_inventory/asset_edit.html'


@register_model_view(models.Asset, 'delete')
class AssetDeleteView(generic.ObjectDeleteView):
queryset = models.Asset.objects.all()

Expand Down Expand Up @@ -117,12 +124,14 @@ def post(self, request, *args, **kwargs):
return super().post(request, *args, **kwargs)


@register_model_view(models.Asset, 'bulk_import', path='import', detail=False)
class AssetBulkImportView(generic.BulkImportView):
queryset = models.Asset.objects.all()
model_form = forms.AssetImportForm
template_name = 'netbox_inventory/asset_bulk_import.html'


@register_model_view(models.Asset, 'bulk_edit', path='edit', detail=False)
class AssetBulkEditView(generic.BulkEditView):
queryset = models.Asset.objects.all()
filterset = filtersets.AssetFilterSet
Expand Down Expand Up @@ -198,6 +207,7 @@ def post(self, request, **kwargs):
return super().post(request, **kwargs)


@register_model_view(models.Asset, 'bulk_delete', path='delete', detail=False)
class AssetBulkDeleteView(generic.BulkDeleteView):
queryset = models.Asset.objects.all()
table = tables.AssetTable
Expand Down
Loading

0 comments on commit 2986fd4

Please sign in to comment.