Skip to content

Commit

Permalink
Fixes #935: Fix form validation error when connecting an interface us…
Browse files Browse the repository at this point in the history
…ing live search
  • Loading branch information
jeremystretch committed Mar 3, 2017
1 parent 03d3bbc commit f051c0e
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,33 +1468,21 @@ def __init__(self, device_a, *args, **kwargs):
]

# Initialize rack_b choices if site_b is set
if self.is_bound and self.data.get('site_b'):
self.fields['rack_b'].queryset = Rack.objects.filter(site__pk=self.data['site_b'])
elif self.initial.get('site_b'):
if self.initial.get('site_b'):
self.fields['rack_b'].queryset = Rack.objects.filter(site=self.initial['site_b'])
else:
self.fields['rack_b'].choices = []

# Initialize device_b choices if rack_b or site_b is set
if self.is_bound and self.data.get('rack_b'):
self.fields['device_b'].queryset = Device.objects.filter(rack__pk=self.data['rack_b'])
elif self.is_bound and self.data.get('site_b'):
self.fields['device_b'].queryset = Device.objects.filter(site__pk=self.data['site_b'], rack__isnull=True)
elif self.initial.get('rack_b'):
if self.initial.get('rack_b'):
self.fields['device_b'].queryset = Device.objects.filter(rack=self.initial['rack_b'])
elif self.initial.get('site_b'):
self.fields['device_b'].queryset = Device.objects.filter(site=self.initial['site_b'], rack__isnull=True)
else:
self.fields['device_b'].choices = []

# Initialize interface_b choices if device_b is set
if self.is_bound:
device_b_interfaces = Interface.objects.filter(device=self.data['device_b']).exclude(
form_factor__in=VIRTUAL_IFACE_TYPES
).select_related(
'circuit_termination', 'connected_as_a', 'connected_as_b'
)
elif self.initial.get('device_b'):
if self.initial.get('device_b'):
device_b_interfaces = Interface.objects.filter(device=self.initial['device_b']).exclude(
form_factor__in=VIRTUAL_IFACE_TYPES
).select_related(
Expand Down

0 comments on commit f051c0e

Please sign in to comment.