mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-09 00:58:16 -06:00
9627 numeric range field
This commit is contained in:
parent
8e67c548af
commit
8f8ba2c86c
@ -914,7 +914,8 @@ class VLANGroupFilterSet(OrganizationalModelFilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
fields = ('id', 'name', 'slug', 'min_vid', 'max_vid', 'description', 'scope_id')
|
fields = ('id', 'name', 'slug', 'description', 'scope_id')
|
||||||
|
# fields = ('id', 'name', 'slug', 'min_vid', 'max_vid', 'description', 'scope_id')
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -486,7 +486,8 @@ class VLANGroupBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
|
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('site', 'min_vid', 'max_vid', 'description'),
|
# FieldSet('site', 'min_vid', 'max_vid', 'description'),
|
||||||
|
FieldSet('site', 'description'),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster', name=_('Scope')
|
'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster', name=_('Scope')
|
||||||
),
|
),
|
||||||
|
@ -413,7 +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('min_vid', 'max_vid', name=_('VLAN ID')),
|
# FieldSet('min_vid', 'max_vid', name=_('VLAN ID')),
|
||||||
)
|
)
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
region = DynamicModelMultipleChoiceField(
|
region = DynamicModelMultipleChoiceField(
|
||||||
@ -441,18 +441,18 @@ class VLANGroupFilterForm(NetBoxModelFilterSetForm):
|
|||||||
required=False,
|
required=False,
|
||||||
label=_('Rack')
|
label=_('Rack')
|
||||||
)
|
)
|
||||||
min_vid = forms.IntegerField(
|
# min_vid = forms.IntegerField(
|
||||||
required=False,
|
# required=False,
|
||||||
min_value=VLAN_VID_MIN,
|
# min_value=VLAN_VID_MIN,
|
||||||
max_value=VLAN_VID_MAX,
|
# max_value=VLAN_VID_MAX,
|
||||||
label=_('Minimum VID')
|
# label=_('Minimum VID')
|
||||||
)
|
# )
|
||||||
max_vid = forms.IntegerField(
|
# max_vid = forms.IntegerField(
|
||||||
required=False,
|
# required=False,
|
||||||
min_value=VLAN_VID_MIN,
|
# min_value=VLAN_VID_MIN,
|
||||||
max_value=VLAN_VID_MAX,
|
# max_value=VLAN_VID_MAX,
|
||||||
label=_('Maximum VID')
|
# label=_('Maximum VID')
|
||||||
)
|
# )
|
||||||
cluster = DynamicModelMultipleChoiceField(
|
cluster = DynamicModelMultipleChoiceField(
|
||||||
queryset=Cluster.objects.all(),
|
queryset=Cluster.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
|
@ -633,15 +633,11 @@ class VLANGroupForm(NetBoxModelForm):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
# vlan_id_ranges = SimpleArrayField(
|
|
||||||
# IntegerRangeField(),
|
|
||||||
# delimiter="|"
|
|
||||||
# )
|
|
||||||
vlan_id_ranges = NumericRangeArrayField()
|
vlan_id_ranges = NumericRangeArrayField()
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('name', 'slug', 'description', 'tags', name=_('VLAN Group')),
|
FieldSet('name', 'slug', 'description', 'tags', name=_('VLAN Group')),
|
||||||
FieldSet('min_vid', 'max_vid', 'vlan_id_ranges', name=_('Child VLANs')),
|
FieldSet('vlan_id_ranges', name=_('Child VLANs')),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster',
|
'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack', 'clustergroup', 'cluster',
|
||||||
name=_('Scope')
|
name=_('Scope')
|
||||||
@ -652,7 +648,7 @@ class VLANGroupForm(NetBoxModelForm):
|
|||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'slug', 'description', 'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack',
|
'name', 'slug', 'description', 'scope_type', 'region', 'sitegroup', 'site', 'location', 'rack',
|
||||||
'clustergroup', 'cluster', 'min_vid', 'max_vid', 'vlan_id_ranges', 'tags',
|
'clustergroup', 'cluster', 'vlan_id_ranges', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -3,6 +3,15 @@
|
|||||||
import django.contrib.postgres.fields
|
import django.contrib.postgres.fields
|
||||||
import django.contrib.postgres.fields.ranges
|
import django.contrib.postgres.fields.ranges
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
from django.db.backends.postgresql.psycopg_any import NumericRange
|
||||||
|
|
||||||
|
|
||||||
|
def move_min_max(apps, schema_editor):
|
||||||
|
VLANGroup = apps.get_model('ipam', 'VLANGroup')
|
||||||
|
for group in VLANGroup.objects.all():
|
||||||
|
if group.min_vid or group.max_vid:
|
||||||
|
group.vlan_id_ranges = [NumericRange(group.min_vid, group.max_vid)]
|
||||||
|
group.save()
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@ -17,4 +26,16 @@ class Migration(migrations.Migration):
|
|||||||
name='vlan_id_ranges',
|
name='vlan_id_ranges',
|
||||||
field=django.contrib.postgres.fields.ArrayField(base_field=django.contrib.postgres.fields.ranges.BigIntegerRangeField(), blank=True, null=True, size=None),
|
field=django.contrib.postgres.fields.ArrayField(base_field=django.contrib.postgres.fields.ranges.BigIntegerRangeField(), blank=True, null=True, size=None),
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
code=move_min_max,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='vlangroup',
|
||||||
|
name='max_vid',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='vlangroup',
|
||||||
|
name='min_vid',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -46,24 +46,6 @@ class VLANGroup(OrganizationalModel):
|
|||||||
ct_field='scope_type',
|
ct_field='scope_type',
|
||||||
fk_field='scope_id'
|
fk_field='scope_id'
|
||||||
)
|
)
|
||||||
min_vid = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('minimum VLAN ID'),
|
|
||||||
default=VLAN_VID_MIN,
|
|
||||||
validators=(
|
|
||||||
MinValueValidator(VLAN_VID_MIN),
|
|
||||||
MaxValueValidator(VLAN_VID_MAX)
|
|
||||||
),
|
|
||||||
help_text=_('Lowest permissible ID of a child VLAN')
|
|
||||||
)
|
|
||||||
max_vid = models.PositiveSmallIntegerField(
|
|
||||||
verbose_name=_('maximum VLAN ID'),
|
|
||||||
default=VLAN_VID_MAX,
|
|
||||||
validators=(
|
|
||||||
MinValueValidator(VLAN_VID_MIN),
|
|
||||||
MaxValueValidator(VLAN_VID_MAX)
|
|
||||||
),
|
|
||||||
help_text=_('Highest permissible ID of a child VLAN')
|
|
||||||
)
|
|
||||||
vlan_id_ranges = ArrayField(
|
vlan_id_ranges = ArrayField(
|
||||||
BigIntegerRangeField(),
|
BigIntegerRangeField(),
|
||||||
verbose_name=_('min/max VLAN IDs'),
|
verbose_name=_('min/max VLAN IDs'),
|
||||||
@ -71,7 +53,6 @@ class VLANGroup(OrganizationalModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
# vlan_id_ranges = BigIntegerRangeField(null=True, blank=True)
|
|
||||||
|
|
||||||
objects = VLANGroupQuerySet.as_manager()
|
objects = VLANGroupQuerySet.as_manager()
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ class VLANGroupQuerySet(RestrictedQuerySet):
|
|||||||
|
|
||||||
return self.annotate(
|
return self.annotate(
|
||||||
vlan_count=count_related(VLAN, 'group'),
|
vlan_count=count_related(VLAN, 'group'),
|
||||||
utilization=Round(F('vlan_count') / (F('max_vid') - F('min_vid') + 1.0) * 100, 2)
|
# utilization=Round(F('vlan_count') / (F('max_vid') - F('min_vid') + 1.0) * 100, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,7 +156,8 @@ class VLANGroupIndex(SearchIndex):
|
|||||||
('description', 500),
|
('description', 500),
|
||||||
('max_vid', 2000),
|
('max_vid', 2000),
|
||||||
)
|
)
|
||||||
display_attrs = ('scope_type', 'min_vid', 'max_vid', 'description')
|
# display_attrs = ('scope_type', 'min_vid', 'max_vid', 'description')
|
||||||
|
display_attrs = ('scope_type', 'description')
|
||||||
|
|
||||||
|
|
||||||
@register_search
|
@register_search
|
||||||
|
@ -91,7 +91,7 @@ class VLANGroupTable(NetBoxTable):
|
|||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = VLANGroup
|
model = VLANGroup
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'scope_type', 'scope', 'min_vid', 'max_vid', 'vlan_count', 'slug', 'description',
|
'pk', 'id', 'name', 'scope_type', 'scope', 'vlan_id_ranges', 'vlan_count', 'slug', 'description',
|
||||||
'tags', 'created', 'last_updated', 'actions', 'utilization',
|
'tags', 'created', 'last_updated', 'actions', 'utilization',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'utilization', 'description')
|
default_columns = ('pk', 'name', 'scope_type', 'scope', 'vlan_count', 'utilization', 'description')
|
||||||
|
@ -52,6 +52,6 @@ class NumericRangeArrayField(forms.CharField):
|
|||||||
ranges = value.split(",")
|
ranges = value.split(",")
|
||||||
values = []
|
values = []
|
||||||
for dash_range in value.split(','):
|
for dash_range in value.split(','):
|
||||||
begin, end = dash_range.split('-')
|
lower, upper = dash_range.split('-')
|
||||||
values.append(NumericRange(begin, end))
|
values.append(NumericRange(lower, upper))
|
||||||
return values
|
return values
|
||||||
|
Loading…
Reference in New Issue
Block a user