Skip to content

Commit

Permalink
Implement bulk imports and edits for SLM models
Browse files Browse the repository at this point in the history
Closes #4
Based on @erichester76's #44

Signed-off-by: wkoot <[email protected]>
  • Loading branch information
Eric Hester authored and wkoot committed Oct 14, 2024
1 parent 3539539 commit 2cd6b74
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 10 deletions.
16 changes: 12 additions & 4 deletions netbox_slm/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
)
23 changes: 21 additions & 2 deletions netbox_slm/forms/software_license.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -46,14 +46,14 @@ class Meta:
fields = (
"name",
"description",
"software_product",
"type",
"stored_location",
"stored_location_url",
"start_date",
"expiration_date",
"support",
"license_amount",
"software_product",
"version",
"installation",
"tags",
Expand All @@ -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",
)
14 changes: 13 additions & 1 deletion netbox_slm/forms/software_product.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
)
16 changes: 15 additions & 1 deletion netbox_slm/forms/software_product_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
)
20 changes: 18 additions & 2 deletions netbox_slm/forms/software_product_version.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,14 +25,14 @@ class Meta:
model = SoftwareProductVersion
fields = (
"name",
"software_product",
"release_date",
"documentation_url",
"end_of_support",
"filename",
"file_checksum",
"file_link",
"release_type",
"software_product",
"tags",
"comments",
)
Expand All @@ -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",
)
24 changes: 24 additions & 0 deletions netbox_slm/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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"],
),
),
),
)
Expand Down
10 changes: 10 additions & 0 deletions netbox_slm/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>/", views.SoftwareProductView.as_view(), name="softwareproduct"),
path(
"software-products/<int:pk>/delete/", views.SoftwareProductDeleteView.as_view(), name="softwareproduct_delete"
Expand All @@ -30,6 +31,9 @@
views.SoftwareProductVersionBulkDeleteView.as_view(),
name="softwareproductversion_bulk_delete",
),
path(
"versions/import/", views.SoftwareProductVersionBulkImportView.as_view(), name="softwareproductversion_import"
),
path("versions/<int:pk>/", views.SoftwareProductVersionView.as_view(), name="softwareproductversion"),
path(
"versions/<int:pk>/delete/",
Expand Down Expand Up @@ -59,6 +63,11 @@
views.SoftwareProductInstallationBulkDeleteView.as_view(),
name="softwareproductinstallation_bulk_delete",
),
path(
"installations/import/",
views.SoftwareProductInstallationBulkImportView.as_view(),
name="softwareproductinstallation_import",
),
path(
"installations/<int:pk>/",
views.SoftwareProductInstallationView.as_view(),
Expand All @@ -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/<int:pk>/", views.SoftwareLicenseView.as_view(), name="softwarelicense"),
path("licenses/<int:pk>/delete/", views.SoftwareLicenseDeleteView.as_view(), name="softwarelicense_delete"),
path("licenses/<int:pk>/edit/", views.SoftwareLicenseEditView.as_view(), name="softwarelicense_edit"),
Expand Down
4 changes: 4 additions & 0 deletions netbox_slm/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
SoftwareLicenseEditView,
SoftwareLicenseDeleteView,
SoftwareLicenseBulkDeleteView,
SoftwareLicenseBulkImportView,
)
from .software_product import (
SoftwareProductListView,
SoftwareProductView,
SoftwareProductEditView,
SoftwareProductDeleteView,
SoftwareProductBulkDeleteView,
SoftwareProductBulkImportView,
)
from .software_product_installation import (
SoftwareProductInstallationListView,
SoftwareProductInstallationView,
SoftwareProductInstallationEditView,
SoftwareProductInstallationDeleteView,
SoftwareProductInstallationBulkDeleteView,
SoftwareProductInstallationBulkImportView,
)
from .software_product_version import (
SoftwareProductVersionListView,
SoftwareProductVersionView,
SoftwareProductVersionEditView,
SoftwareProductVersionDeleteView,
SoftwareProductVersionBulkDeleteView,
SoftwareProductVersionBulkImportView,
)
6 changes: 6 additions & 0 deletions netbox_slm/views/software_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions netbox_slm/views/software_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions netbox_slm/views/software_product_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions netbox_slm/views/software_product_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2cd6b74

Please sign in to comment.