Skip to content

Commit

Permalink
Fixes #4523 - Add site vlan to certain scenarios where sites are the …
Browse files Browse the repository at this point in the history
…same
  • Loading branch information
DanSheps committed Sep 29, 2020
1 parent 015e25c commit ee7f43a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,24 @@ def __init__(self, *args, **kwargs):
self.fields['untagged_vlan'].widget.add_query_param('site_id', device.site.pk)
self.fields['tagged_vlans'].widget.add_query_param('site_id', device.site.pk)
else:
# See 4523
if 'pk' in self.initial:
site = None
interfaces = Interface.objects.filter(pk__in=self.initial['pk']).prefetch_related('device__site')

# Check interface sites. First interface should set site, further interfaces will either continue the
# loop or reset back to no site and break the loop.
for interface in interfaces:
if site is None:
site = interface.device.site
elif interface.device.site is not site:
site = None
break

if site is not None:
self.fields['untagged_vlan'].widget.add_query_param('site_id', site.pk)
self.fields['tagged_vlans'].widget.add_query_param('site_id', site.pk)

self.fields['lag'].choices = ()
self.fields['lag'].widget.attrs['disabled'] = True

Expand Down

0 comments on commit ee7f43a

Please sign in to comment.