From 2cd6b745ded348d5b3d07800abc887aca29fd84d Mon Sep 17 00:00:00 2001 From: Eric Hester Date: Sun, 13 Oct 2024 17:22:59 -0400 Subject: [PATCH] Implement bulk imports and edits for SLM models Closes #4 Based on @erichester76's https://github.com/ICTU/netbox_slm/pull/44 Signed-off-by: wkoot <3715211+wkoot@users.noreply.github.com> --- netbox_slm/forms/__init__.py | 16 +++++++++---- netbox_slm/forms/software_license.py | 23 ++++++++++++++++-- netbox_slm/forms/software_product.py | 14 ++++++++++- .../forms/software_product_installation.py | 16 ++++++++++++- netbox_slm/forms/software_product_version.py | 20 ++++++++++++++-- netbox_slm/navigation.py | 24 +++++++++++++++++++ netbox_slm/urls.py | 10 ++++++++ netbox_slm/views/__init__.py | 4 ++++ netbox_slm/views/software_license.py | 6 +++++ netbox_slm/views/software_product.py | 6 +++++ .../views/software_product_installation.py | 6 +++++ netbox_slm/views/software_product_version.py | 6 +++++ 12 files changed, 141 insertions(+), 10 deletions(-) diff --git a/netbox_slm/forms/__init__.py b/netbox_slm/forms/__init__.py index f8d7033..254091a 100644 --- a/netbox_slm/forms/__init__.py +++ b/netbox_slm/forms/__init__.py @@ -1,4 +1,12 @@ -from .software_license import SoftwareLicenseForm, SoftwareLicenseFilterForm -from .software_product import SoftwareProductForm, SoftwareProductFilterForm -from .software_product_installation import SoftwareProductInstallationForm, SoftwareProductInstallationFilterForm -from .software_product_version import SoftwareProductVersionForm, SoftwareProductVersionFilterForm +from .software_license import SoftwareLicenseForm, SoftwareLicenseFilterForm, SoftwareLicenseBulkImportForm +from .software_product import SoftwareProductForm, SoftwareProductFilterForm, SoftwareProductBulkImportForm +from .software_product_installation import ( + SoftwareProductInstallationForm, + SoftwareProductInstallationFilterForm, + SoftwareProductInstallationBulkImportForm, +) +from .software_product_version import ( + SoftwareProductVersionForm, + SoftwareProductVersionFilterForm, + SoftwareProductVersionBulkImportForm, +) diff --git a/netbox_slm/forms/software_license.py b/netbox_slm/forms/software_license.py index c0dbc67..92b5371 100644 --- a/netbox_slm/forms/software_license.py +++ b/netbox_slm/forms/software_license.py @@ -1,7 +1,7 @@ from django.forms import DateField from django.urls import reverse_lazy -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, LaxURLField from utilities.forms.rendering import FieldSet @@ -46,6 +46,7 @@ class Meta: fields = ( "name", "description", + "software_product", "type", "stored_location", "stored_location_url", @@ -53,7 +54,6 @@ class Meta: "expiration_date", "support", "license_amount", - "software_product", "version", "installation", "tags", @@ -65,3 +65,22 @@ class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm): model = SoftwareLicense fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + + +class SoftwareLicenseBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareLicense + fields = ( + "name", + "description", + "software_product", + "type", + "start_date", + "expiration_date", + "support", + "license_amount", + "version", + "installation", + "tags", + "comments", + ) diff --git a/netbox_slm/forms/software_product.py b/netbox_slm/forms/software_product.py index 5e920d5..0420b2d 100644 --- a/netbox_slm/forms/software_product.py +++ b/netbox_slm/forms/software_product.py @@ -1,5 +1,5 @@ from dcim.models import Manufacturer -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProduct from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -30,3 +30,15 @@ class SoftwareProductFilterForm(NetBoxModelFilterSetForm): model = SoftwareProduct fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + + +class SoftwareProductBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareProduct + fields = ( + "name", + "description", + "manufacturer", + "tags", + "comments", + ) diff --git a/netbox_slm/forms/software_product_installation.py b/netbox_slm/forms/software_product_installation.py index f3d036e..9baf048 100644 --- a/netbox_slm/forms/software_product_installation.py +++ b/netbox_slm/forms/software_product_installation.py @@ -2,7 +2,7 @@ from django.urls import reverse_lazy from dcim.models import Device -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProductInstallation, SoftwareProduct, SoftwareProductVersion from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -59,3 +59,17 @@ class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm): model = SoftwareProductInstallation fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + + +class SoftwareProductInstallationBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareProductInstallation + fields = ( + "device", + "virtualmachine", + "cluster", + "software_product", + "version", + "tags", + "comments", + ) diff --git a/netbox_slm/forms/software_product_version.py b/netbox_slm/forms/software_product_version.py index fd2c74f..fcbbcad 100644 --- a/netbox_slm/forms/software_product_version.py +++ b/netbox_slm/forms/software_product_version.py @@ -1,7 +1,7 @@ from django.forms import DateField from django.urls import reverse_lazy -from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm +from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm from netbox_slm.models import SoftwareProduct, SoftwareProductVersion from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField from utilities.forms.rendering import FieldSet @@ -25,6 +25,7 @@ class Meta: model = SoftwareProductVersion fields = ( "name", + "software_product", "release_date", "documentation_url", "end_of_support", @@ -32,7 +33,6 @@ class Meta: "file_checksum", "file_link", "release_type", - "software_product", "tags", "comments", ) @@ -42,3 +42,19 @@ class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm): model = SoftwareProductVersion fieldsets = (FieldSet(None, ("q", "tag")),) tag = TagFilterField(model) + + +class SoftwareProductVersionBulkImportForm(NetBoxModelImportForm): + class Meta: + model = SoftwareProductVersion + fields = ( + "name", + "software_product", + "release_date", + "end_of_support", + "filename", + "file_checksum", + "release_type", + "tags", + "comments", + ) diff --git a/netbox_slm/navigation.py b/netbox_slm/navigation.py index 78cf3dd..8bc921b 100644 --- a/netbox_slm/navigation.py +++ b/netbox_slm/navigation.py @@ -15,6 +15,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproduct"], ), + PluginMenuButton( + "plugins:netbox_slm:softwareproduct_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwareproduct"], + ), ), ), PluginMenuItem( @@ -28,6 +34,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproductversion"], ), + PluginMenuButton( + "plugins:netbox_slm:softwareproductversion_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwareproductversion"], + ), ), ), PluginMenuItem( @@ -41,6 +53,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwareproductinstallation"], ), + PluginMenuButton( + "plugins:netbox_slm:softwareproductinstallation_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwareproductinstallation"], + ), ), ), PluginMenuItem( @@ -54,6 +72,12 @@ "mdi mdi-plus-thick", permissions=["netbox_slm.add_softwarelicense"], ), + PluginMenuButton( + "plugins:netbox_slm:softwarelicense_import", + "Import", + "mdi mdi-upload", + permissions=["netbox_slm.import_softwarelicense"], + ), ), ), ) diff --git a/netbox_slm/urls.py b/netbox_slm/urls.py index 4856d47..2c33a95 100644 --- a/netbox_slm/urls.py +++ b/netbox_slm/urls.py @@ -11,6 +11,7 @@ path( "software-products/delete/", views.SoftwareProductBulkDeleteView.as_view(), name="softwareproduct_bulk_delete" ), + path("software-products/import/", views.SoftwareProductBulkImportView.as_view(), name="softwareproduct_import"), path("software-products//", views.SoftwareProductView.as_view(), name="softwareproduct"), path( "software-products//delete/", views.SoftwareProductDeleteView.as_view(), name="softwareproduct_delete" @@ -30,6 +31,9 @@ views.SoftwareProductVersionBulkDeleteView.as_view(), name="softwareproductversion_bulk_delete", ), + path( + "versions/import/", views.SoftwareProductVersionBulkImportView.as_view(), name="softwareproductversion_import" + ), path("versions//", views.SoftwareProductVersionView.as_view(), name="softwareproductversion"), path( "versions//delete/", @@ -59,6 +63,11 @@ views.SoftwareProductInstallationBulkDeleteView.as_view(), name="softwareproductinstallation_bulk_delete", ), + path( + "installations/import/", + views.SoftwareProductInstallationBulkImportView.as_view(), + name="softwareproductinstallation_import", + ), path( "installations//", views.SoftwareProductInstallationView.as_view(), @@ -84,6 +93,7 @@ path("licenses/", views.SoftwareLicenseListView.as_view(), name="softwarelicense_list"), path("licenses/add/", views.SoftwareLicenseEditView.as_view(), name="softwarelicense_add"), path("licenses/delete/", views.SoftwareLicenseBulkDeleteView.as_view(), name="softwarelicense_bulk_delete"), + path("licenses/import/", views.SoftwareLicenseBulkImportView.as_view(), name="softwarelicense_import"), path("licenses//", views.SoftwareLicenseView.as_view(), name="softwarelicense"), path("licenses//delete/", views.SoftwareLicenseDeleteView.as_view(), name="softwarelicense_delete"), path("licenses//edit/", views.SoftwareLicenseEditView.as_view(), name="softwarelicense_edit"), diff --git a/netbox_slm/views/__init__.py b/netbox_slm/views/__init__.py index 6a54180..3dc5830 100644 --- a/netbox_slm/views/__init__.py +++ b/netbox_slm/views/__init__.py @@ -4,6 +4,7 @@ SoftwareLicenseEditView, SoftwareLicenseDeleteView, SoftwareLicenseBulkDeleteView, + SoftwareLicenseBulkImportView, ) from .software_product import ( SoftwareProductListView, @@ -11,6 +12,7 @@ SoftwareProductEditView, SoftwareProductDeleteView, SoftwareProductBulkDeleteView, + SoftwareProductBulkImportView, ) from .software_product_installation import ( SoftwareProductInstallationListView, @@ -18,6 +20,7 @@ SoftwareProductInstallationEditView, SoftwareProductInstallationDeleteView, SoftwareProductInstallationBulkDeleteView, + SoftwareProductInstallationBulkImportView, ) from .software_product_version import ( SoftwareProductVersionListView, @@ -25,4 +28,5 @@ SoftwareProductVersionEditView, SoftwareProductVersionDeleteView, SoftwareProductVersionBulkDeleteView, + SoftwareProductVersionBulkImportView, ) diff --git a/netbox_slm/views/software_license.py b/netbox_slm/views/software_license.py index b57e754..eca9dcc 100644 --- a/netbox_slm/views/software_license.py +++ b/netbox_slm/views/software_license.py @@ -34,3 +34,9 @@ class SoftwareLicenseDeleteView(generic.ObjectDeleteView): class SoftwareLicenseBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareLicense.objects.all() table = tables.SoftwareLicenseTable + + +class SoftwareLicenseBulkImportView(generic.BulkImportView): + queryset = SoftwareLicense.objects.all() + table = tables.SoftwareLicenseTable + model_form = forms.SoftwareLicenseBulkImportForm diff --git a/netbox_slm/views/software_product.py b/netbox_slm/views/software_product.py index 2d8e6a8..622d3ec 100644 --- a/netbox_slm/views/software_product.py +++ b/netbox_slm/views/software_product.py @@ -38,3 +38,9 @@ class SoftwareProductDeleteView(generic.ObjectDeleteView): class SoftwareProductBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareProduct.objects.all() table = tables.SoftwareProductTable + + +class SoftwareProductBulkImportView(generic.BulkImportView): + queryset = SoftwareProduct.objects.all() + table = tables.SoftwareProductTable + model_form = forms.SoftwareProductBulkImportForm diff --git a/netbox_slm/views/software_product_installation.py b/netbox_slm/views/software_product_installation.py index f0cf444..c5eb407 100644 --- a/netbox_slm/views/software_product_installation.py +++ b/netbox_slm/views/software_product_installation.py @@ -34,3 +34,9 @@ class SoftwareProductInstallationDeleteView(generic.ObjectDeleteView): class SoftwareProductInstallationBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareProductInstallation.objects.all() table = tables.SoftwareProductInstallationTable + + +class SoftwareProductInstallationBulkImportView(generic.BulkImportView): + queryset = SoftwareProductInstallation.objects.all() + table = tables.SoftwareProductInstallationTable + model_form = forms.SoftwareProductInstallationBulkImportForm diff --git a/netbox_slm/views/software_product_version.py b/netbox_slm/views/software_product_version.py index 7f89fca..c495ae7 100644 --- a/netbox_slm/views/software_product_version.py +++ b/netbox_slm/views/software_product_version.py @@ -38,3 +38,9 @@ class SoftwareProductVersionDeleteView(generic.ObjectDeleteView): class SoftwareProductVersionBulkDeleteView(generic.BulkDeleteView): queryset = SoftwareProductVersion.objects.all() table = tables.SoftwareProductVersionTable + + +class SoftwareProductVersionBulkImportView(generic.BulkImportView): + queryset = SoftwareProductVersion.objects.all() + table = tables.SoftwareProductVersionTable + model_form = forms.SoftwareProductVersionBulkImportForm