From 722c7ba6af038582c0e164ba9e002b7d1b1c9e4d Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Mon, 28 Oct 2024 15:31:36 -0400 Subject: [PATCH] Add description field to VLANTranslationRule --- netbox/ipam/filtersets.py | 2 +- netbox/ipam/forms/filtersets.py | 6 +----- netbox/ipam/forms/model_forms.py | 4 ++-- .../0074_vlantranslationpolicy_vlantranslationrule.py | 1 + netbox/ipam/models/vlans.py | 5 +++++ netbox/ipam/tests/test_api.py | 3 +++ netbox/ipam/tests/test_filtersets.py | 7 +++++++ netbox/templates/ipam/vlantranslationrule.html | 4 ++++ 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index 2e20027f1..a72042f5a 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -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(): diff --git a/netbox/ipam/forms/filtersets.py b/netbox/ipam/forms/filtersets.py index be492c90d..b9bee6d97 100644 --- a/netbox/ipam/forms/filtersets.py +++ b/netbox/ipam/forms/filtersets.py @@ -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) diff --git a/netbox/ipam/forms/model_forms.py b/netbox/ipam/forms/model_forms.py index 08cac3f29..629c1a481 100644 --- a/netbox/ipam/forms/model_forms.py +++ b/netbox/ipam/forms/model_forms.py @@ -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', ] diff --git a/netbox/ipam/migrations/0074_vlantranslationpolicy_vlantranslationrule.py b/netbox/ipam/migrations/0074_vlantranslationpolicy_vlantranslationrule.py index 4b35ea9e7..ca3943649 100644 --- a/netbox/ipam/migrations/0074_vlantranslationpolicy_vlantranslationrule.py +++ b/netbox/ipam/migrations/0074_vlantranslationpolicy_vlantranslationrule.py @@ -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={ diff --git a/netbox/ipam/models/vlans.py b/netbox/ipam/models/vlans.py index 1d14615c1..ff8394839 100644 --- a/netbox/ipam/models/vlans.py +++ b/netbox/ipam/models/vlans.py @@ -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=( diff --git a/netbox/ipam/tests/test_api.py b/netbox/ipam/tests/test_api.py index 8a08a7143..cd3e47342 100644 --- a/netbox/ipam/tests/test_api.py +++ b/netbox/ipam/tests/test_api.py @@ -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) diff --git a/netbox/ipam/tests/test_filtersets.py b/netbox/ipam/tests/test_filtersets.py index 575cbe6e3..d6902a64f 100644 --- a/netbox/ipam/tests/test_filtersets.py +++ b/netbox/ipam/tests/test_filtersets.py @@ -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() diff --git a/netbox/templates/ipam/vlantranslationrule.html b/netbox/templates/ipam/vlantranslationrule.html index 32e1883c3..b63992073 100644 --- a/netbox/templates/ipam/vlantranslationrule.html +++ b/netbox/templates/ipam/vlantranslationrule.html @@ -22,6 +22,10 @@ {% trans "Remote VID" %} {{ object.remote_vid }} + + {% trans "Description" %} + {{ object.description }} + {% plugin_left_page object %}