Skip to content

Commit

Permalink
Fixes #409: Filter IPs and prefixes by tenant slug rather than by its PK
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Aug 2, 2016
1 parent 3327954 commit 249faff
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions netbox/ipam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def prefix_vrf_choices():
return [(v.pk, u'{} ({})'.format(v.name, v.prefix_count)) for v in vrf_choices]


def tenant_choices():
tenant_choices = Tenant.objects.all()
return [(t.slug, t.name) for t in tenant_choices]


def prefix_site_choices():
site_choices = Site.objects.annotate(prefix_count=Count('prefixes'))
return [(s.slug, u'{} ({})'.format(s.name, s.prefix_count)) for s in site_choices]
Expand All @@ -291,8 +296,8 @@ class PrefixFilterForm(forms.Form, BootstrapMixin):
parent = forms.CharField(required=False, label='Search Within')
vrf = forms.MultipleChoiceField(required=False, choices=prefix_vrf_choices, label='VRF',
widget=forms.SelectMultiple(attrs={'size': 6}))
tenant = forms.ModelMultipleChoiceField(queryset=Tenant.objects.all(), required=False,
widget=forms.SelectMultiple(attrs={'size': 6}))
tenant = forms.MultipleChoiceField(required=False, choices=tenant_choices, label='Tenant',
widget=forms.SelectMultiple(attrs={'size': 6}))
status = forms.MultipleChoiceField(required=False, choices=prefix_status_choices,
widget=forms.SelectMultiple(attrs={'size': 6}))
site = forms.MultipleChoiceField(required=False, choices=prefix_site_choices,
Expand Down Expand Up @@ -442,8 +447,8 @@ class IPAddressFilterForm(forms.Form, BootstrapMixin):
family = forms.ChoiceField(required=False, choices=ipaddress_family_choices, label='Address Family')
vrf = forms.MultipleChoiceField(required=False, choices=ipaddress_vrf_choices, label='VRF',
widget=forms.SelectMultiple(attrs={'size': 6}))
tenant = forms.ModelMultipleChoiceField(queryset=Tenant.objects.all(), required=False,
widget=forms.SelectMultiple(attrs={'size': 6}))
tenant = forms.MultipleChoiceField(required=False, choices=tenant_choices, label='Tenant',
widget=forms.SelectMultiple(attrs={'size': 6}))


#
Expand Down

0 comments on commit 249faff

Please sign in to comment.