fixed filter search
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ to install the Netbox SLM plugin:
|
||||
|
||||
1. Add ``netbox_slm`` to the ``PLUGINS`` list in
|
||||
``configuration/extra.py``.
|
||||
2. Create a ``plugin_requirements.txt`` with ``netbox-slm==0.99`` as
|
||||
2. Create a ``plugin_requirements.txt`` with ``netbox-slm==1.01`` as
|
||||
contents.
|
||||
3. Create a ``Dockerfile-SLM`` with contents:
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ class SLMConfig(PluginConfig):
|
||||
name = 'netbox_slm'
|
||||
verbose_name = 'Software Lifecycle Management'
|
||||
description = 'Software Lifecycle Management'
|
||||
version = '0.99'
|
||||
version = '1.01'
|
||||
author = 'Hedde van der Heide'
|
||||
author_email = 'hedde.vanderheide@ictu.nl'
|
||||
base_url = 'slm'
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
from django.contrib import admin
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion
|
||||
|
||||
|
||||
class SoftwareProductVersionInline(admin.TabularInline):
|
||||
model = SoftwareProductVersion
|
||||
fields = ('name',)
|
||||
extra = 0
|
||||
|
||||
|
||||
@admin.register(SoftwareProduct)
|
||||
class SoftwareProductAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
inlines = (SoftwareProductVersionInline,)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from django.db.models import Q
|
||||
|
||||
from netbox.filtersets import NetBoxModelFilterSet
|
||||
from netbox_slm.models import *
|
||||
|
||||
@@ -8,6 +10,14 @@ class SoftwareProductFilterSet(NetBoxModelFilterSet):
|
||||
model = SoftwareProduct
|
||||
fields = tuple()
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
"""Perform the filtered search."""
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = Q(name__icontains=value) | \
|
||||
Q(manufacturer__name__icontains=value)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class SoftwareProductVersionFilterSet(NetBoxModelFilterSet):
|
||||
"""Filter capabilities for SoftwareProductVersion instances."""
|
||||
@@ -15,9 +25,27 @@ class SoftwareProductVersionFilterSet(NetBoxModelFilterSet):
|
||||
model = SoftwareProductVersion
|
||||
fields = tuple()
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
"""Perform the filtered search."""
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = Q(name__icontains=value) | \
|
||||
Q(software_product__name__icontains=value) | \
|
||||
Q(software_product__manufacturer__name__icontains=value)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class SoftwareProductInstallationFilterSet(NetBoxModelFilterSet):
|
||||
"""Filter capabilities for SoftwareProductInstallation instances."""
|
||||
class Meta:
|
||||
model = SoftwareProductInstallation
|
||||
fields = tuple()
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
"""Perform the filtered search."""
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = Q(software_product__name__icontains=value) | \
|
||||
Q(software_product__manufacturer__name__icontains=value) | \
|
||||
Q(version__name__icontains=value)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
+2
-29
@@ -1,5 +1,4 @@
|
||||
from django import forms
|
||||
from django.db.models import Q
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
@@ -12,7 +11,7 @@ from netbox.forms import (
|
||||
)
|
||||
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation
|
||||
from utilities.forms import (
|
||||
DynamicModelChoiceField, APISelect, TagFilterField
|
||||
DynamicModelChoiceField, APISelect, TagFilterField, ChoiceField
|
||||
)
|
||||
from virtualization.models import VirtualMachine
|
||||
|
||||
@@ -38,14 +37,6 @@ class SoftwareProductFilterForm(NetBoxModelFilterSetForm):
|
||||
|
||||
tag = TagFilterField(model)
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
"""Perform the filtered search."""
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = Q(name__icontains=value) | \
|
||||
Q(manufacturer__name__icontains=value)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class SoftwareProductCSVForm(NetBoxModelCSVForm):
|
||||
class Meta:
|
||||
@@ -88,15 +79,6 @@ class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm):
|
||||
|
||||
tag = TagFilterField(model)
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
"""Perform the filtered search."""
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = Q(name__icontains=value) | \
|
||||
Q(software_product__name__icontains=value) | \
|
||||
Q(software_product__manufacturer__name__icontains=value)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class SoftwareProductVersionCSVForm(NetBoxModelCSVForm):
|
||||
class Meta:
|
||||
@@ -165,20 +147,11 @@ class SoftwareProductInstallationForm(NetBoxModelForm):
|
||||
class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm):
|
||||
model = SoftwareProductInstallation
|
||||
fieldsets = (
|
||||
(None, ('q', 'tag')),
|
||||
(None, ('q', 'tag',)),
|
||||
)
|
||||
|
||||
tag = TagFilterField(model)
|
||||
|
||||
def search(self, queryset, name, value):
|
||||
"""Perform the filtered search."""
|
||||
if not value.strip():
|
||||
return queryset
|
||||
qs_filter = Q(software_product__name__icontains=value) | \
|
||||
Q(software_product__manufacturer__name__icontains=value) | \
|
||||
Q(version__name__icontains=value)
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class SoftwareProductInstallationCSVForm(NetBoxModelCSVForm):
|
||||
class Meta:
|
||||
|
||||
Reference in New Issue
Block a user