@@ -4,13 +4,15 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
from netbox.forms import NetBoxModelForm, NetBoxModelImportForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
|
||||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
||||||
from utilities.forms.fields import DynamicModelChoiceField, TagFilterField
|
from utilities.forms.fields import DynamicModelChoiceField, TagFilterField, LaxURLField
|
||||||
from utilities.forms.widgets import APISelect, DatePicker
|
from utilities.forms.widgets import APISelect, DatePicker
|
||||||
|
|
||||||
|
|
||||||
class SoftwareLicenseForm(NetBoxModelForm):
|
class SoftwareLicenseForm(NetBoxModelForm):
|
||||||
"""Form for creating a new SoftwareLicense object."""
|
"""Form for creating a new SoftwareLicense object."""
|
||||||
|
|
||||||
|
stored_location_url = LaxURLField(required=False)
|
||||||
|
|
||||||
software_product = DynamicModelChoiceField(
|
software_product = DynamicModelChoiceField(
|
||||||
queryset=SoftwareProduct.objects.all(),
|
queryset=SoftwareProduct.objects.all(),
|
||||||
required=True,
|
required=True,
|
||||||
@@ -44,6 +46,7 @@ class SoftwareLicenseForm(NetBoxModelForm):
|
|||||||
"description",
|
"description",
|
||||||
"type",
|
"type",
|
||||||
"stored_location",
|
"stored_location",
|
||||||
|
"stored_location_url",
|
||||||
"start_date",
|
"start_date",
|
||||||
"expiration_date",
|
"expiration_date",
|
||||||
"software_product",
|
"software_product",
|
||||||
@@ -76,6 +79,7 @@ class SoftwareLicenseImportForm(NetBoxModelImportForm):
|
|||||||
"description",
|
"description",
|
||||||
"type",
|
"type",
|
||||||
"stored_location",
|
"stored_location",
|
||||||
|
"stored_location_url",
|
||||||
"start_date",
|
"start_date",
|
||||||
"expiration_date",
|
"expiration_date",
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.2.5 on 2023-09-22 00:34
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import netbox_slm.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('netbox_slm', '0005_add_software_license'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='softwarelicense',
|
||||||
|
name='stored_location_url',
|
||||||
|
field=netbox_slm.models.LaxURLField(blank=True, max_length=1024, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -4,6 +4,16 @@ from django.utils import safestring
|
|||||||
|
|
||||||
from netbox.models import NetBoxModel
|
from netbox.models import NetBoxModel
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
from utilities.validators import EnhancedURLValidator
|
||||||
|
|
||||||
|
|
||||||
|
class LaxURLField(models.URLField):
|
||||||
|
"""
|
||||||
|
NetBox Custom Field approach, based on utilities.forms.fields.LaxURLField
|
||||||
|
Overriding default_validators is needed, as they are always added
|
||||||
|
"""
|
||||||
|
|
||||||
|
default_validators = [EnhancedURLValidator()]
|
||||||
|
|
||||||
|
|
||||||
class SoftwareProduct(NetBoxModel):
|
class SoftwareProduct(NetBoxModel):
|
||||||
@@ -94,6 +104,7 @@ class SoftwareLicense(NetBoxModel):
|
|||||||
type = models.CharField(max_length=128)
|
type = models.CharField(max_length=128)
|
||||||
|
|
||||||
stored_location = models.CharField(max_length=255, null=True, blank=True)
|
stored_location = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
stored_location_url = LaxURLField(max_length=1024, null=True, blank=True)
|
||||||
start_date = models.DateField(null=True, blank=True)
|
start_date = models.DateField(null=True, blank=True)
|
||||||
expiration_date = models.DateField(null=True, blank=True)
|
expiration_date = models.DateField(null=True, blank=True)
|
||||||
|
|
||||||
@@ -110,3 +121,9 @@ class SoftwareLicense(NetBoxModel):
|
|||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("plugins:netbox_slm:softwarelicense", kwargs={"pk": self.pk})
|
return reverse("plugins:netbox_slm:softwarelicense", kwargs={"pk": self.pk})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def stored_location_txt(self):
|
||||||
|
if self.stored_location_url and not self.stored_location:
|
||||||
|
return "Link"
|
||||||
|
return self.stored_location
|
||||||
|
|||||||
+14
-13
@@ -1,6 +1,5 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from django_tables2.utils import Accessor
|
|
||||||
|
|
||||||
from netbox.tables import NetBoxTable, ToggleColumn, columns
|
from netbox.tables import NetBoxTable, ToggleColumn, columns
|
||||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
||||||
@@ -11,7 +10,7 @@ class SoftwareProductTable(NetBoxTable):
|
|||||||
|
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.LinkColumn()
|
name = tables.LinkColumn()
|
||||||
manufacturer = tables.Column(accessor=Accessor("manufacturer"), linkify=True)
|
manufacturer = tables.Column(accessor="manufacturer", linkify=True)
|
||||||
installations = tables.Column(accessor="get_installation_count", verbose_name="Installations")
|
installations = tables.Column(accessor="get_installation_count", verbose_name="Installations")
|
||||||
|
|
||||||
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproduct_list")
|
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproduct_list")
|
||||||
@@ -53,8 +52,8 @@ class SoftwareProductVersionTable(NetBoxTable):
|
|||||||
|
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.LinkColumn(verbose_name="Version")
|
name = tables.LinkColumn(verbose_name="Version")
|
||||||
software_product = tables.Column(accessor=Accessor("software_product"), linkify=True)
|
software_product = tables.Column(accessor="software_product", linkify=True)
|
||||||
manufacturer = tables.Column(accessor=Accessor("software_product__manufacturer"), linkify=True)
|
manufacturer = tables.Column(accessor="software_product__manufacturer", linkify=True)
|
||||||
installations = tables.Column(accessor="get_installation_count", verbose_name="Installations")
|
installations = tables.Column(accessor="get_installation_count", verbose_name="Installations")
|
||||||
|
|
||||||
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductversion_list")
|
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductversion_list")
|
||||||
@@ -96,12 +95,12 @@ class SoftwareProductInstallationTable(NetBoxTable):
|
|||||||
|
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.LinkColumn()
|
name = tables.LinkColumn()
|
||||||
device = tables.Column(accessor=Accessor("device"), linkify=True)
|
device = tables.Column(accessor="device", linkify=True)
|
||||||
virtualmachine = tables.Column(accessor=Accessor("virtualmachine"), linkify=True)
|
virtualmachine = tables.Column(accessor="virtualmachine", linkify=True)
|
||||||
platform = tables.Column(accessor=Accessor("platform"), linkify=True)
|
platform = tables.Column(accessor="platform", linkify=True)
|
||||||
type = tables.Column(accessor="render_type")
|
type = tables.Column(accessor="render_type")
|
||||||
software_product = tables.Column(accessor=Accessor("software_product"), linkify=True)
|
software_product = tables.Column(accessor="software_product", linkify=True)
|
||||||
version = tables.Column(accessor=Accessor("version"), linkify=True)
|
version = tables.Column(accessor="version", linkify=True)
|
||||||
|
|
||||||
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductinstallation_list")
|
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductinstallation_list")
|
||||||
|
|
||||||
@@ -143,10 +142,12 @@ class SoftwareLicenseTable(NetBoxTable):
|
|||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.LinkColumn()
|
name = tables.LinkColumn()
|
||||||
|
|
||||||
type = tables.Column(accessor="render_type")
|
type = tables.Column()
|
||||||
software_product = tables.Column(accessor=Accessor("software_product"), linkify=True)
|
stored_location = tables.Column(accessor="stored_location_txt", linkify=lambda record: record.stored_location_url)
|
||||||
version = tables.Column(accessor=Accessor("version"), linkify=True)
|
|
||||||
installation = tables.Column(accessor=Accessor("installation"), linkify=True)
|
software_product = tables.Column(accessor="software_product", linkify=True)
|
||||||
|
version = tables.Column(accessor="version", linkify=True)
|
||||||
|
installation = tables.Column(accessor="installation", linkify=True)
|
||||||
|
|
||||||
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwarelicense_list")
|
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwarelicense_list")
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Stored location</th>
|
<th scope="row">Stored location</th>
|
||||||
<td>{{ object.stored_location }}</td>
|
{% if object.stored_location_url %}
|
||||||
|
<td><a href="{{ object.stored_location_url }}">{{ object.stored_location_txt }}</a></td>
|
||||||
|
{% else %}
|
||||||
|
<td>{{ object.stored_location_txt }}</td>
|
||||||
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Start date</th>
|
<th scope="row">Start date</th>
|
||||||
|
|||||||
Reference in New Issue
Block a user