Add description field to VLANTranslationRule

This commit is contained in:
Brian Tiemann 2024-10-28 15:31:36 -04:00
parent d9dde5c4f4
commit 722c7ba6af
8 changed files with 24 additions and 8 deletions

View File

@ -1130,7 +1130,7 @@ class VLANTranslationRuleFilterSet(NetBoxModelFilterSet):
class Meta:
model = VLANTranslationRule
fields = ('id', 'policy_id', 'local_vid', 'remote_vid')
fields = ('id', 'policy_id', 'local_vid', 'remote_vid', 'description')
def search(self, queryset, name, value):
if not value.strip():

View File

@ -467,16 +467,12 @@ class VLANTranslationPolicyFilterForm(NetBoxModelFilterSetForm):
model = VLANTranslationPolicy
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('name', 'description', name=_('Attributes')),
FieldSet('name', name=_('Attributes')),
)
name = forms.CharField(
required=False,
label=_('Name')
)
description = forms.CharField(
required=False,
label=_('Name')
)
tag = TagFilterField(model)

View File

@ -714,13 +714,13 @@ class VLANTranslationRuleForm(NetBoxModelForm):
)
fieldsets = (
FieldSet('policy', 'local_vid', 'remote_vid', 'tags', name=_('VLAN Translation Rule')),
FieldSet('policy', 'local_vid', 'remote_vid', 'description', 'tags', name=_('VLAN Translation Rule')),
)
class Meta:
model = VLANTranslationRule
fields = [
'policy', 'local_vid', 'remote_vid', 'tags',
'policy', 'local_vid', 'remote_vid', 'description', 'tags',
]

View File

@ -43,6 +43,7 @@ class Migration(migrations.Migration):
('local_vid', models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4094)])),
('remote_vid', models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(4094)])),
('policy', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rules', to='ipam.vlantranslationpolicy')),
('description', models.CharField(blank=True, max_length=200)),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
],
options={

View File

@ -299,6 +299,11 @@ class VLANTranslationRule(NetBoxModel):
related_name='rules',
on_delete=models.CASCADE,
)
description = models.CharField(
verbose_name=_('description'),
max_length=200,
blank=True
)
local_vid = models.PositiveSmallIntegerField(
verbose_name=_('Local VLAN ID'),
validators=(

View File

@ -1086,16 +1086,19 @@ class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase):
policy=vlan_translation_policies[0],
local_vid=100,
remote_vid=200,
description='foo',
),
VLANTranslationRule(
policy=vlan_translation_policies[0],
local_vid=101,
remote_vid=201,
description='bar',
),
VLANTranslationRule(
policy=vlan_translation_policies[1],
local_vid=102,
remote_vid=202,
description='baz',
),
)
VLANTranslationRule.objects.bulk_create(vlan_translation_rules)

View File

@ -1954,16 +1954,19 @@ class VLANTranslationRuleTestCase(TestCase, ChangeLoggedFilterSetTests):
policy=vlan_translation_policies[0],
local_vid=100,
remote_vid=200,
description='foo',
),
VLANTranslationRule(
policy=vlan_translation_policies[0],
local_vid=101,
remote_vid=201,
description='bar',
),
VLANTranslationRule(
policy=vlan_translation_policies[1],
local_vid=100,
remote_vid=200,
description='baz',
),
)
VLANTranslationRule.objects.bulk_create(vlan_translation_rules)
@ -1981,6 +1984,10 @@ class VLANTranslationRuleTestCase(TestCase, ChangeLoggedFilterSetTests):
params = {'remote_vid': [200]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
def test_description(self):
params = {'description': ['foo', 'bar']}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
class ServiceTemplateTestCase(TestCase, ChangeLoggedFilterSetTests):
queryset = ServiceTemplate.objects.all()

View File

@ -22,6 +22,10 @@
<th scope="row">{% trans "Remote VID" %}</th>
<td>{{ object.remote_vid }}</td>
</tr>
<tr>
<th scope="row">{% trans "Description" %}</th>
<td>{{ object.description }}</td>
</tr>
</table>
</div>
{% plugin_left_page object %}