Fix unencoded search link of installations table cells (#53)
Closes #48 Signed-off-by: wkoot <3715211+wkoot@users.noreply.github.com>
This commit is contained in:
+14
-20
@@ -1,9 +1,15 @@
|
||||
from django_filters import CharFilter, ModelMultipleChoiceFilter, MultipleChoiceFilter
|
||||
from django.db.models import Q
|
||||
from django_filters import CharFilter, ModelMultipleChoiceFilter, MultipleChoiceFilter
|
||||
|
||||
from dcim.models import Device, Manufacturer
|
||||
from netbox.filtersets import NetBoxModelFilterSet
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense, SoftwareReleaseTypes
|
||||
from netbox_slm.models import (
|
||||
SoftwareProduct,
|
||||
SoftwareProductVersion,
|
||||
SoftwareProductInstallation,
|
||||
SoftwareLicense,
|
||||
SoftwareReleaseTypes,
|
||||
)
|
||||
from virtualization.models import VirtualMachine, Cluster
|
||||
|
||||
|
||||
@@ -13,9 +19,7 @@ class SoftwareProductFilterSet(NetBoxModelFilterSet):
|
||||
name = CharFilter(lookup_expr="icontains")
|
||||
description = CharFilter(lookup_expr="icontains")
|
||||
|
||||
manufacturer = ModelMultipleChoiceFilter(
|
||||
queryset=Manufacturer.objects.all()
|
||||
)
|
||||
manufacturer = ModelMultipleChoiceFilter(queryset=Manufacturer.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = SoftwareProduct
|
||||
@@ -72,23 +76,17 @@ class SoftwareProductVersionFilterSet(NetBoxModelFilterSet):
|
||||
class SoftwareProductInstallationFilterSet(NetBoxModelFilterSet):
|
||||
"""Filter capabilities for SoftwareProductInstallation instances."""
|
||||
|
||||
device = ModelMultipleChoiceFilter(
|
||||
queryset=Device.objects.all()
|
||||
)
|
||||
device = ModelMultipleChoiceFilter(queryset=Device.objects.all())
|
||||
virtualmachine = ModelMultipleChoiceFilter(
|
||||
queryset=VirtualMachine.objects.all(),
|
||||
label="Virtual Machine",
|
||||
)
|
||||
cluster = ModelMultipleChoiceFilter(
|
||||
queryset=Cluster.objects.all()
|
||||
)
|
||||
cluster = ModelMultipleChoiceFilter(queryset=Cluster.objects.all())
|
||||
software_product = ModelMultipleChoiceFilter(
|
||||
queryset=SoftwareProduct.objects.all(),
|
||||
label="Software Product",
|
||||
)
|
||||
version = ModelMultipleChoiceFilter(
|
||||
queryset=SoftwareProductVersion.objects.all()
|
||||
)
|
||||
version = ModelMultipleChoiceFilter(queryset=SoftwareProductVersion.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = SoftwareProductInstallation
|
||||
@@ -119,12 +117,8 @@ class SoftwareLicenseFilterSet(NetBoxModelFilterSet):
|
||||
queryset=SoftwareProduct.objects.all(),
|
||||
label="Software Product",
|
||||
)
|
||||
version = ModelMultipleChoiceFilter(
|
||||
queryset=SoftwareProductVersion.objects.all()
|
||||
)
|
||||
installation = ModelMultipleChoiceFilter(
|
||||
queryset=SoftwareProductInstallation.objects.all()
|
||||
)
|
||||
version = ModelMultipleChoiceFilter(queryset=SoftwareProductVersion.objects.all())
|
||||
installation = ModelMultipleChoiceFilter(queryset=SoftwareProductInstallation.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = SoftwareLicense
|
||||
|
||||
@@ -4,7 +4,13 @@ from django.urls import reverse_lazy
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
||||
from utilities.forms.constants import BOOLEAN_WITH_BLANK_CHOICES
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, LaxURLField, DynamicModelMultipleChoiceField
|
||||
from utilities.forms.fields import (
|
||||
CommentField,
|
||||
DynamicModelChoiceField,
|
||||
TagFilterField,
|
||||
LaxURLField,
|
||||
DynamicModelMultipleChoiceField,
|
||||
)
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.widgets import APISelect, DatePicker
|
||||
|
||||
@@ -67,7 +73,9 @@ class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm):
|
||||
model = SoftwareLicense
|
||||
fieldsets = (
|
||||
FieldSet("q", "filter_id", "tag"),
|
||||
FieldSet("name", "description", "type", "stored_location", "support", "software_product", "version", "installation"),
|
||||
FieldSet(
|
||||
"name", "description", "type", "stored_location", "support", "software_product", "version", "installation"
|
||||
),
|
||||
)
|
||||
selector_fields = ("q", "filter_id", "name")
|
||||
|
||||
|
||||
@@ -3,7 +3,12 @@ from django.forms import CharField
|
||||
from dcim.models import Manufacturer
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm
|
||||
from netbox_slm.models import SoftwareProduct
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, DynamicModelMultipleChoiceField
|
||||
from utilities.forms.fields import (
|
||||
CommentField,
|
||||
DynamicModelChoiceField,
|
||||
TagFilterField,
|
||||
DynamicModelMultipleChoiceField,
|
||||
)
|
||||
from utilities.forms.rendering import FieldSet
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,12 @@ from django.urls import reverse_lazy
|
||||
from dcim.models import Device
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm
|
||||
from netbox_slm.models import SoftwareProductInstallation, SoftwareProduct, SoftwareProductVersion
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, DynamicModelMultipleChoiceField
|
||||
from utilities.forms.fields import (
|
||||
CommentField,
|
||||
DynamicModelChoiceField,
|
||||
TagFilterField,
|
||||
DynamicModelMultipleChoiceField,
|
||||
)
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.widgets import APISelect
|
||||
from virtualization.models import VirtualMachine, Cluster
|
||||
|
||||
@@ -4,7 +4,12 @@ from django.urls import reverse_lazy
|
||||
from dcim.models import Manufacturer
|
||||
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm, NetBoxModelImportForm
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareReleaseTypes
|
||||
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, DynamicModelMultipleChoiceField
|
||||
from utilities.forms.fields import (
|
||||
CommentField,
|
||||
DynamicModelChoiceField,
|
||||
TagFilterField,
|
||||
DynamicModelMultipleChoiceField,
|
||||
)
|
||||
from utilities.forms.rendering import FieldSet
|
||||
from utilities.forms.widgets import APISelect, DatePicker
|
||||
|
||||
|
||||
+10
-22
@@ -1,6 +1,6 @@
|
||||
from django.db import models
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import safestring
|
||||
from django.urls import reverse
|
||||
from django.utils.html import format_html, urlencode
|
||||
|
||||
from netbox.models import NetBoxModel
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
@@ -33,16 +33,10 @@ class SoftwareProduct(NetBoxModel):
|
||||
|
||||
def get_installation_count(self):
|
||||
count = SoftwareProductInstallation.objects.filter(software_product_id=self.pk).count()
|
||||
return (
|
||||
safestring.mark_safe(
|
||||
'<a href="{url}">{count}</a>'.format(
|
||||
url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}",
|
||||
count=count,
|
||||
)
|
||||
)
|
||||
if count
|
||||
else "0"
|
||||
)
|
||||
query_string = urlencode(dict(software_product=self.pk))
|
||||
search_target = reverse("plugins:netbox_slm:softwareproductinstallation_list")
|
||||
# Can be composed directly with reverse(query=) in Django 5.2, see https://code.djangoproject.com/ticket/25582
|
||||
return format_html(f"<a href='{search_target}?{query_string}'>{count}</a>") if count else "0"
|
||||
|
||||
|
||||
class SoftwareReleaseTypes(models.TextChoices):
|
||||
@@ -84,16 +78,10 @@ class SoftwareProductVersion(NetBoxModel):
|
||||
|
||||
def get_installation_count(self):
|
||||
count = SoftwareProductInstallation.objects.filter(version_id=self.pk).count()
|
||||
return (
|
||||
safestring.mark_safe(
|
||||
'<a href="{url}">{count}</a>'.format(
|
||||
url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}",
|
||||
count=count,
|
||||
)
|
||||
)
|
||||
if count
|
||||
else "0"
|
||||
)
|
||||
query_string = urlencode(dict(version=self.pk))
|
||||
search_target = reverse("plugins:netbox_slm:softwareproductinstallation_list")
|
||||
# Can be composed directly with reverse(query=) in Django 5.2, see https://code.djangoproject.com/ticket/25582
|
||||
return format_html(f"<a href='{search_target}?{query_string}'>{count}</a>") if count else "0"
|
||||
|
||||
|
||||
class SoftwareProductInstallation(NetBoxModel):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
|
||||
from virtualization.models import Cluster, ClusterType, VirtualMachine
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
||||
from virtualization.models import Cluster, ClusterType, VirtualMachine
|
||||
|
||||
|
||||
class ModelTestCase(TestCase):
|
||||
@@ -49,9 +49,14 @@ class ModelTestCase(TestCase):
|
||||
self.assertEqual("/plugins/slm/licenses/1/", self.software_license.get_absolute_url())
|
||||
|
||||
def test_get_installation_count(self):
|
||||
installation_ss = '<a href="/plugins/slm/installations/?q={}">1</a>'
|
||||
self.assertEqual(installation_ss.format(self.p_name), self.software_product.get_installation_count())
|
||||
self.assertEqual(installation_ss.format(self.v_name), self.software_product_version.get_installation_count())
|
||||
self.assertEqual(
|
||||
f"<a href='/plugins/slm/installations/?software_product={self.software_product.pk}'>1</a>",
|
||||
self.software_product.get_installation_count(),
|
||||
)
|
||||
self.assertEqual(
|
||||
f"<a href='/plugins/slm/installations/?version={self.software_product_version.pk}'>1</a>",
|
||||
self.software_product_version.get_installation_count(),
|
||||
)
|
||||
|
||||
def test_product_installation_methods(self):
|
||||
self.assertEqual("virtualmachine", self.software_product_installation.render_type())
|
||||
|
||||
Reference in New Issue
Block a user