mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 16:48:16 -06:00
9627 temp vlan_id filter
This commit is contained in:
parent
ff9197ebe0
commit
bbfcba4b93
@ -911,6 +911,9 @@ class VLANGroupFilterSet(OrganizationalModelFilterSet):
|
|||||||
cluster = django_filters.NumberFilter(
|
cluster = django_filters.NumberFilter(
|
||||||
method='filter_scope'
|
method='filter_scope'
|
||||||
)
|
)
|
||||||
|
vlan_id = django_filters.NumberFilter(
|
||||||
|
method='filter_vlan_id'
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
@ -932,6 +935,11 @@ class VLANGroupFilterSet(OrganizationalModelFilterSet):
|
|||||||
scope_id=value
|
scope_id=value
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def filter_vlan_id(self, queryset, name, value):
|
||||||
|
return queryset.filter(
|
||||||
|
vid_range__contained_by=value
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VLANFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
|
class VLANFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
|
||||||
region_id = TreeNodeMultipleChoiceFilter(
|
region_id = TreeNodeMultipleChoiceFilter(
|
||||||
|
@ -413,6 +413,7 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
|||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag'),
|
||||||
FieldSet('region', 'sitegroup', 'site', 'location', 'rack', name=_('Location')),
|
FieldSet('region', 'sitegroup', 'site', 'location', 'rack', name=_('Location')),
|
||||||
FieldSet('cluster_group', 'cluster', name=_('Cluster')),
|
FieldSet('cluster_group', 'cluster', name=_('Cluster')),
|
||||||
|
FieldSet('vlan_id', name=_('VLAN ID')),
|
||||||
)
|
)
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
region = DynamicModelMultipleChoiceField(
|
region = DynamicModelMultipleChoiceField(
|
||||||
@ -450,6 +451,11 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
|||||||
required=False,
|
required=False,
|
||||||
label=_('Cluster group')
|
label=_('Cluster group')
|
||||||
)
|
)
|
||||||
|
vlan_id = forms.IntegerField(
|
||||||
|
min_value=0,
|
||||||
|
required=False,
|
||||||
|
label=_('Contains VLAN ID')
|
||||||
|
)
|
||||||
|
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import Count, F, OuterRef, Q, Subquery, Value
|
from django.db.models import Count, Func, F, OuterRef, Q, Subquery, Value
|
||||||
from django.db.models.expressions import RawSQL
|
from django.db.models.expressions import RawSQL
|
||||||
from django.db.models.functions import Round
|
from django.db.models.functions import Round
|
||||||
|
|
||||||
@ -66,6 +66,12 @@ class VLANGroupQuerySet(RestrictedQuerySet):
|
|||||||
utilization=Round(F('vlan_count') * 100 / F('_total_vlan_ids'), 2)
|
utilization=Round(F('vlan_count') * 100 / F('_total_vlan_ids'), 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def annotate_vlan_ranges(self):
|
||||||
|
|
||||||
|
return self.annotate(
|
||||||
|
vid_range=Func(F('vlan_id_ranges'), function='unnest')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class VLANQuerySet(RestrictedQuerySet):
|
class VLANQuerySet(RestrictedQuerySet):
|
||||||
|
|
||||||
|
@ -915,7 +915,7 @@ class IPAddressContactsView(ObjectContactsView):
|
|||||||
#
|
#
|
||||||
|
|
||||||
class VLANGroupListView(generic.ObjectListView):
|
class VLANGroupListView(generic.ObjectListView):
|
||||||
queryset = VLANGroup.objects.annotate_utilization().prefetch_related('tags')
|
queryset = VLANGroup.objects.annotate_utilization().annotate_vlan_ranges().prefetch_related('tags')
|
||||||
filterset = filtersets.VLANGroupFilterSet
|
filterset = filtersets.VLANGroupFilterSet
|
||||||
filterset_form = forms.VLANGroupFilterForm
|
filterset_form = forms.VLANGroupFilterForm
|
||||||
table = tables.VLANGroupTable
|
table = tables.VLANGroupTable
|
||||||
|
Loading…
Reference in New Issue
Block a user