From 51736942e710d45352b711b76bbba0ea42498f40 Mon Sep 17 00:00:00 2001 From: Hedde van der Heide Date: Thu, 24 Mar 2022 11:15:53 +0100 Subject: [PATCH] fixed display bug installations detail, merged device/vm columns and added type for installations table view --- src/README.rst | 3 ++- src/netbox_slm/api/serializers.py | 2 +- src/netbox_slm/models.py | 7 +++++++ src/netbox_slm/tables.py | 16 ++++++++++++---- .../netbox_slm/softwareproductversion.html | 6 +----- src/netbox_slm/views.py | 6 +++--- src/setup.cfg | 1 - 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/README.rst b/src/README.rst index 557ceed..1b5dca3 100644 --- a/src/README.rst +++ b/src/README.rst @@ -20,7 +20,7 @@ to install the Netbox SLM plugin: 1. Add ``netbox_slm`` to the ``PLUGINS`` list in ``configuration/configuration.py``. -2. Create a ``plugin_requirements.txt`` with ``netbox-slm==0.9`` as +2. Create a ``plugin_requirements.txt`` with ``netbox-slm==0.93`` as contents. 3. Create a ``Dockerfile-SLM`` with contents: @@ -63,6 +63,7 @@ directory run :: + # make sure to update the version in netbox_slm/__init__.py $ python setup.py sdist $ twine upload dist/* diff --git a/src/netbox_slm/api/serializers.py b/src/netbox_slm/api/serializers.py index 05a4ec3..a214eae 100644 --- a/src/netbox_slm/api/serializers.py +++ b/src/netbox_slm/api/serializers.py @@ -21,7 +21,7 @@ class SoftwareProductSerializer(PrimaryModelSerializer): ] def get_display(self, obj): - return obj.name + return f"{obj.manufacturer.name} - {obj.name}" class SoftwareProductVersionSerializer(PrimaryModelSerializer): diff --git a/src/netbox_slm/models.py b/src/netbox_slm/models.py index 89449d7..941946b 100644 --- a/src/netbox_slm/models.py +++ b/src/netbox_slm/models.py @@ -55,6 +55,7 @@ class SoftwareProductVersion(PrimaryModel): return reverse("plugins:netbox_slm:softwareproductversion", kwargs={"pk": self.pk}) def get_installation_count(self): + print("ACCESSED") count = SoftwareProductInstallation.objects.filter(version_id=self.pk).count() return safestring.mark_safe("{count}".format( url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}", @@ -96,3 +97,9 @@ class SoftwareProductInstallation(PrimaryModel): def get_absolute_url(self): return reverse("plugins:netbox_slm:softwareproductinstallation", kwargs={"pk": self.pk}) + + def get_platform(self): + return self.device or self.virtualmachine + + def render_type(self): + return f"{'device' if self.device else 'virtualmachine'}" diff --git a/src/netbox_slm/tables.py b/src/netbox_slm/tables.py index 840d34c..379bf68 100644 --- a/src/netbox_slm/tables.py +++ b/src/netbox_slm/tables.py @@ -91,6 +91,11 @@ class SoftwareProductInstallationTable(BaseTable): accessor=Accessor('virtualmachine'), linkify=True ) + platform = tables.Column( + accessor='get_platform', + linkify=True + ) + type = tables.Column(accessor='render_type') software_product = tables.Column( accessor=Accessor('software_product'), linkify=True @@ -109,17 +114,20 @@ class SoftwareProductInstallationTable(BaseTable): fields = ( "pk", "name", - "device", - "virtualmachine", + "platform", + "type", "software_product", "version", # "tags", ) default_columns = ( "pk", - "device", - "virtualmachine", + "platform", + "type", "software_product", "version", # "tags", ) + + def render_software_product(self, value, **kwargs): + return f"{kwargs['record'].software_product.manufacturer.name} - {value}" diff --git a/src/netbox_slm/templates/netbox_slm/softwareproductversion.html b/src/netbox_slm/templates/netbox_slm/softwareproductversion.html index 6853b61..ed5db57 100644 --- a/src/netbox_slm/templates/netbox_slm/softwareproductversion.html +++ b/src/netbox_slm/templates/netbox_slm/softwareproductversion.html @@ -25,11 +25,7 @@ Installations - - - - - + {{ object.get_installation_count }} diff --git a/src/netbox_slm/views.py b/src/netbox_slm/views.py index 82b96e4..836e486 100644 --- a/src/netbox_slm/views.py +++ b/src/netbox_slm/views.py @@ -78,9 +78,9 @@ class SoftwareProductVersionView(generic.ObjectView): queryset = SoftwareProductVersion.objects.all() - # def get_extra_context(self, request, instance): - # records = instance.record_set.all() - # return {"records": records} + def get_extra_context(self, request, instance): + installation_count = instance.get_installation_count() + return {"installations": installation_count} class SoftwareProductVersionEditView(generic.ObjectEditView): diff --git a/src/setup.cfg b/src/setup.cfg index a7c2753..d3fab40 100644 --- a/src/setup.cfg +++ b/src/setup.cfg @@ -16,7 +16,6 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9