From d73ff19d71b4bd47c1568cbc24883613320e54d3 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 21 Dec 2016 11:06:42 -0500 Subject: [PATCH] Fixes #563: Allow a device to be flipped from one rack face to the other --- netbox/dcim/api/views.py | 6 +++++- netbox/dcim/forms.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index 621f937fb..8b598339f 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -118,7 +118,11 @@ class RackUnitListView(APIView): rack = get_object_or_404(Rack, pk=pk) face = request.GET.get('face', 0) - elevation = rack.get_rack_units(face) + try: + exclude = int(request.GET.get('exclude', None)) + except ValueError: + exclude = None + elevation = rack.get_rack_units(face, exclude) # Serialize Devices within the rack elevation for u in elevation: diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 13603f179..85dc34883 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -419,6 +419,10 @@ class DeviceForm(BootstrapMixin, CustomFieldForm): ip_choices += [(ip.id, u'{} ({} NAT)'.format(ip.address, ip.nat_inside.interface)) for ip in nat_ips] self.fields['primary_ip{}'.format(family)].choices = [(None, '---------')] + ip_choices + # If editing an existing device, exclude it from the list of occupied rack units. This ensures that a device + # can be flipped from one face to another. + self.fields['position'].widget.attrs['api-url'] += '&exclude={}'.format(self.instance.pk) + else: # An object that doesn't exist yet can't have any IPs assigned to it