Skip to content

Commit

Permalink
#7025: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Aug 29, 2024
1 parent 6f7bf5b commit 9a11191
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
21 changes: 19 additions & 2 deletions netbox/circuits/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,26 @@ class CircuitGroupAssignmentFilterSet(NetBoxModelFilterSet):
method='search',
label=_('Search'),
)
provider_id = django_filters.ModelMultipleChoiceFilter(
field_name='circuit__provider',
queryset=Provider.objects.all(),
label=_('Provider (ID)'),
)
provider = django_filters.ModelMultipleChoiceFilter(
field_name='circuit__provider__slug',
queryset=Provider.objects.all(),
to_field_name='slug',
label=_('Provider (slug)'),
)
circuit_id = django_filters.ModelMultipleChoiceFilter(
queryset=Circuit.objects.all(),
label=_('Circuit'),
label=_('Circuit (ID)'),
)
circuit = django_filters.ModelMultipleChoiceFilter(
field_name='circuit__cid',
queryset=Circuit.objects.all(),
to_field_name='cid',
label=_('Circuit (CID)'),
)
group_id = django_filters.ModelMultipleChoiceFilter(
queryset=CircuitGroup.objects.all(),
Expand All @@ -336,7 +353,7 @@ class CircuitGroupAssignmentFilterSet(NetBoxModelFilterSet):

class Meta:
model = CircuitGroupAssignment
fields = ('id', 'circuit', 'group', 'priority')
fields = ('id', 'priority')

def search(self, queryset, name, value):
if not value.strip():
Expand Down
7 changes: 6 additions & 1 deletion netbox/circuits/forms/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,12 @@ class CircuitGroupAssignmentFilterForm(NetBoxModelFilterSetForm):
model = CircuitGroupAssignment
fieldsets = (
FieldSet('q', 'filter_id', 'tag'),
FieldSet('circuit_id', 'group_id', 'priority', name=_('Assignment')),
FieldSet('provider_id', 'circuit_id', 'group_id', 'priority', name=_('Assignment')),
)
provider_id = DynamicModelMultipleChoiceField(
queryset=Provider.objects.all(),
required=False,
label=_('Provider')
)
circuit_id = DynamicModelMultipleChoiceField(
queryset=Circuit.objects.all(),
Expand Down
9 changes: 7 additions & 2 deletions netbox/circuits/tables/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class CircuitGroupAssignmentTable(NetBoxTable):
verbose_name=_('Group'),
linkify=True
)
provider = tables.Column(
accessor='circuit__provider',
verbose_name=_('Provider'),
linkify=True
)
circuit = tables.Column(
verbose_name=_('Circuit'),
linkify=True
Expand All @@ -169,6 +174,6 @@ class CircuitGroupAssignmentTable(NetBoxTable):
class Meta(NetBoxTable.Meta):
model = CircuitGroupAssignment
fields = (
'pk', 'id', 'group', 'circuit', 'priority', 'created', 'last_updated', 'actions', 'tags',
'pk', 'id', 'group', 'provider', 'circuit', 'priority', 'created', 'last_updated', 'actions', 'tags',
)
default_columns = ('pk', 'group', 'circuit', 'priority')
default_columns = ('pk', 'group', 'provider', 'circuit', 'priority')
28 changes: 21 additions & 7 deletions netbox/circuits/tests/test_filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,19 @@ def setUpTestData(cls):
)
CircuitGroup.objects.bulk_create(circuit_groups)

provider = Provider.objects.create(name='Provider 1', slug='provider-1')
providers = Provider.objects.bulk_create((
Provider(name='Provider 1', slug='provider-1'),
Provider(name='Provider 2', slug='provider-2'),
Provider(name='Provider 3', slug='provider-3'),
Provider(name='Provider 4', slug='provider-4'),
))
circuittype = CircuitType.objects.create(name='Circuit Type 1', slug='circuit-type-1')

circuits = (
Circuit(cid='Circuit 1', provider=provider, type=circuittype),
Circuit(cid='Circuit 2', provider=provider, type=circuittype),
Circuit(cid='Circuit 3', provider=provider, type=circuittype),
Circuit(cid='Circuit 4', provider=provider, type=circuittype),
Circuit(cid='Circuit 1', provider=providers[0], type=circuittype),
Circuit(cid='Circuit 2', provider=providers[1], type=circuittype),
Circuit(cid='Circuit 3', provider=providers[2], type=circuittype),
Circuit(cid='Circuit 4', provider=providers[3], type=circuittype),
)
Circuit.objects.bulk_create(circuits)

Expand Down Expand Up @@ -561,10 +566,19 @@ def test_group_id(self):
params = {'group': [groups[0].slug, groups[1].slug]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_circuit_id(self):
circuits = Circuit.objects.filter(cid__in=['Circuit 1', 'Circuit 2'])
def test_circuit(self):
circuits = Circuit.objects.all()[:2]
params = {'circuit_id': [circuits[0].pk, circuits[1].pk]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
params = {'circuit': [circuits[0].cid, circuits[1].cid]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)

def test_provider(self):
providers = Provider.objects.all()[:2]
params = {'provider_id': [providers[0].pk, providers[1].pk]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
params = {'provider': [providers[0].slug, providers[1].slug]}
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)


class ProviderNetworkTestCase(TestCase, ChangeLoggedFilterSetTests):
Expand Down

0 comments on commit 9a11191

Please sign in to comment.