Add new fields to models and upgrade to NetBox v3.7.2 (#36)
Closes #10, #26, #35
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
from django.forms import DateField
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
||||
from utilities.forms.fields import DynamicModelChoiceField, TagFilterField, LaxURLField
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, LaxURLField
|
||||
from utilities.forms.widgets import APISelect, DatePicker
|
||||
|
||||
|
||||
class SoftwareLicenseForm(NetBoxModelForm):
|
||||
"""Form for creating a new SoftwareLicense object."""
|
||||
|
||||
comments = CommentField()
|
||||
|
||||
stored_location_url = LaxURLField(required=False)
|
||||
|
||||
software_product = DynamicModelChoiceField(
|
||||
@@ -36,8 +37,8 @@ class SoftwareLicenseForm(NetBoxModelForm):
|
||||
"software_product": "$software_product",
|
||||
},
|
||||
)
|
||||
start_date = DateField(label=_("Start date"), required=False, widget=DatePicker())
|
||||
expiration_date = DateField(label=_("Expiration date"), required=False, widget=DatePicker())
|
||||
start_date = DateField(required=False, widget=DatePicker())
|
||||
expiration_date = DateField(required=False, widget=DatePicker())
|
||||
|
||||
class Meta:
|
||||
model = SoftwareLicense
|
||||
@@ -49,25 +50,19 @@ class SoftwareLicenseForm(NetBoxModelForm):
|
||||
"stored_location_url",
|
||||
"start_date",
|
||||
"expiration_date",
|
||||
"support",
|
||||
"license_amount",
|
||||
"software_product",
|
||||
"version",
|
||||
"installation",
|
||||
"tags",
|
||||
"comments",
|
||||
)
|
||||
|
||||
|
||||
class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm):
|
||||
model = SoftwareLicense
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
(
|
||||
"q",
|
||||
"tag",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
fieldsets = ((None, ("q", "tag")),)
|
||||
tag = TagFilterField(model)
|
||||
|
||||
|
||||
|
||||
@@ -3,12 +3,14 @@ from django import forms
|
||||
from dcim.models import Manufacturer
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
||||
from netbox_slm.models import SoftwareProduct
|
||||
from utilities.forms.fields import DynamicModelChoiceField, TagFilterField
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField
|
||||
|
||||
|
||||
class SoftwareProductForm(NetBoxModelForm):
|
||||
"""Form for creating a new SoftwareProduct object."""
|
||||
|
||||
comments = CommentField()
|
||||
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=True,
|
||||
@@ -16,13 +18,18 @@ class SoftwareProductForm(NetBoxModelForm):
|
||||
|
||||
class Meta:
|
||||
model = SoftwareProduct
|
||||
fields = ("name", "manufacturer", "description", "tags")
|
||||
fields = (
|
||||
"name",
|
||||
"description",
|
||||
"manufacturer",
|
||||
"tags",
|
||||
"comments",
|
||||
)
|
||||
|
||||
|
||||
class SoftwareProductFilterForm(NetBoxModelFilterSetForm):
|
||||
model = SoftwareProduct
|
||||
fieldsets = ((None, ("q", "tag")),)
|
||||
|
||||
tag = TagFilterField(model)
|
||||
|
||||
|
||||
@@ -31,6 +38,7 @@ class SoftwareProductImportForm(NetBoxModelImportForm):
|
||||
model = SoftwareProduct
|
||||
fields = (
|
||||
"name",
|
||||
"description",
|
||||
"manufacturer",
|
||||
)
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
from django import forms
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from dcim.models import Device
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
||||
from netbox_slm.models import SoftwareProductInstallation, SoftwareProduct, SoftwareProductVersion
|
||||
from utilities.forms.fields import DynamicModelChoiceField, TagFilterField
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField
|
||||
from utilities.forms.widgets import APISelect
|
||||
from virtualization.models import VirtualMachine, Cluster
|
||||
|
||||
@@ -13,6 +12,8 @@ from virtualization.models import VirtualMachine, Cluster
|
||||
class SoftwareProductInstallationForm(NetBoxModelForm):
|
||||
"""Form for creating a new SoftwareProductInstallation object."""
|
||||
|
||||
comments = CommentField()
|
||||
|
||||
device = DynamicModelChoiceField(queryset=Device.objects.all(), required=False)
|
||||
virtualmachine = DynamicModelChoiceField(queryset=VirtualMachine.objects.all(), required=False)
|
||||
cluster = DynamicModelChoiceField(queryset=Cluster.objects.all(), required=False)
|
||||
@@ -32,33 +33,30 @@ class SoftwareProductInstallationForm(NetBoxModelForm):
|
||||
|
||||
class Meta:
|
||||
model = SoftwareProductInstallation
|
||||
fields = ("device", "virtualmachine", "cluster", "software_product", "version", "tags")
|
||||
fields = (
|
||||
"device",
|
||||
"virtualmachine",
|
||||
"cluster",
|
||||
"software_product",
|
||||
"version",
|
||||
"tags",
|
||||
"comments",
|
||||
)
|
||||
|
||||
def clean_version(self):
|
||||
version = self.cleaned_data["version"]
|
||||
software_product = self.cleaned_data["software_product"]
|
||||
if version not in software_product.softwareproductversion_set.all():
|
||||
raise forms.ValidationError(
|
||||
_(
|
||||
f"Version `{version}` doesn't exist on {software_product}, make sure you've "
|
||||
f"selected a compatible version or first select the software product."
|
||||
)
|
||||
f"Version '{version}' doesn't exist on {software_product}, make sure you've "
|
||||
f"selected a compatible version or first select the software product."
|
||||
)
|
||||
return version
|
||||
|
||||
|
||||
class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm):
|
||||
model = SoftwareProductInstallation
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
(
|
||||
"q",
|
||||
"tag",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
fieldsets = ((None, ("q", "tag")),)
|
||||
tag = TagFilterField(model)
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
from django import forms
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion
|
||||
from utilities.forms.fields import DynamicModelChoiceField, TagFilterField
|
||||
from utilities.forms.widgets import APISelect
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField
|
||||
from utilities.forms.widgets import APISelect, DatePicker
|
||||
|
||||
|
||||
class SoftwareProductVersionForm(NetBoxModelForm):
|
||||
"""Form for creating a new SoftwareProductVersion object."""
|
||||
|
||||
name = forms.CharField(label=_("Version"))
|
||||
comments = CommentField()
|
||||
|
||||
release_date = forms.DateField(required=False, widget=DatePicker())
|
||||
end_of_support = forms.DateField(required=False, widget=DatePicker())
|
||||
|
||||
software_product = DynamicModelChoiceField(
|
||||
queryset=SoftwareProduct.objects.all(),
|
||||
@@ -20,13 +22,24 @@ class SoftwareProductVersionForm(NetBoxModelForm):
|
||||
|
||||
class Meta:
|
||||
model = SoftwareProductVersion
|
||||
fields = ("name", "software_product", "tags")
|
||||
fields = (
|
||||
"name",
|
||||
"release_date",
|
||||
"documentation_url",
|
||||
"end_of_support",
|
||||
"filename",
|
||||
"file_checksum",
|
||||
"file_link",
|
||||
"release_type",
|
||||
"software_product",
|
||||
"tags",
|
||||
"comments",
|
||||
)
|
||||
|
||||
|
||||
class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm):
|
||||
model = SoftwareProductVersion
|
||||
fieldsets = ((None, ("q", "tag")),)
|
||||
|
||||
tag = TagFilterField(model)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user