mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 03:27:21 -06:00
Allow unassigning VRF and tenants when editing objects in bulk
This commit is contained in:
parent
6b41794e12
commit
397943b222
@ -2,6 +2,7 @@ from django import forms
|
|||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
|
||||||
from dcim.models import Site, Device, Interface, Rack, IFACE_FF_VIRTUAL
|
from dcim.models import Site, Device, Interface, Rack, IFACE_FF_VIRTUAL
|
||||||
|
from tenancy.forms import bulkedit_tenant_choices
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms import (
|
from utilities.forms import (
|
||||||
APISelect, BootstrapMixin, BulkImportForm, CommentField, CSVDataField, Livesearch, SmallTextarea, SlugField,
|
APISelect, BootstrapMixin, BulkImportForm, CommentField, CSVDataField, Livesearch, SmallTextarea, SlugField,
|
||||||
@ -180,7 +181,7 @@ class CircuitBulkEditForm(forms.Form, BootstrapMixin):
|
|||||||
pk = forms.ModelMultipleChoiceField(queryset=Circuit.objects.all(), widget=forms.MultipleHiddenInput)
|
pk = forms.ModelMultipleChoiceField(queryset=Circuit.objects.all(), widget=forms.MultipleHiddenInput)
|
||||||
type = forms.ModelChoiceField(queryset=CircuitType.objects.all(), required=False)
|
type = forms.ModelChoiceField(queryset=CircuitType.objects.all(), required=False)
|
||||||
provider = forms.ModelChoiceField(queryset=Provider.objects.all(), required=False)
|
provider = forms.ModelChoiceField(queryset=Provider.objects.all(), required=False)
|
||||||
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
tenant = forms.TypedChoiceField(choices=bulkedit_tenant_choices, coerce=int, required=False, label='Tenant')
|
||||||
port_speed = forms.IntegerField(required=False, label='Port speed (Kbps)')
|
port_speed = forms.IntegerField(required=False, label='Port speed (Kbps)')
|
||||||
commit_rate = forms.IntegerField(required=False, label='Commit rate (Kbps)')
|
commit_rate = forms.IntegerField(required=False, label='Commit rate (Kbps)')
|
||||||
comments = CommentField()
|
comments = CommentField()
|
||||||
|
@ -159,7 +159,11 @@ class CircuitBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
for field in ['type', 'provider', 'tenant', 'port_speed', 'commit_rate', 'comments']:
|
if form.cleaned_data['tenant'] == 0:
|
||||||
|
fields_to_update['tenant'] = None
|
||||||
|
elif form.cleaned_data['tenant']:
|
||||||
|
fields_to_update['tenant'] = form.cleaned_data['tenant']
|
||||||
|
for field in ['type', 'provider', 'port_speed', 'commit_rate', 'comments']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ from django import forms
|
|||||||
from django.db.models import Count, Q
|
from django.db.models import Count, Q
|
||||||
|
|
||||||
from ipam.models import IPAddress
|
from ipam.models import IPAddress
|
||||||
|
from tenancy.forms import bulkedit_tenant_choices
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms import (
|
from utilities.forms import (
|
||||||
APISelect, BootstrapMixin, BulkImportForm, CommentField, CSVDataField, ExpandableNameField,
|
APISelect, BootstrapMixin, BulkImportForm, CommentField, CSVDataField, ExpandableNameField,
|
||||||
@ -39,6 +40,15 @@ def get_device_by_name_or_pk(name):
|
|||||||
return device
|
return device
|
||||||
|
|
||||||
|
|
||||||
|
def bulkedit_platform_choices():
|
||||||
|
choices = [
|
||||||
|
(None, '---------'),
|
||||||
|
(0, 'None'),
|
||||||
|
]
|
||||||
|
choices += [(p.pk, p.name) for p in Platform.objects.all()]
|
||||||
|
return choices
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sites
|
# Sites
|
||||||
#
|
#
|
||||||
@ -78,7 +88,7 @@ class SiteImportForm(BulkImportForm, BootstrapMixin):
|
|||||||
|
|
||||||
class SiteBulkEditForm(forms.Form, BootstrapMixin):
|
class SiteBulkEditForm(forms.Form, BootstrapMixin):
|
||||||
pk = forms.ModelMultipleChoiceField(queryset=Site.objects.all(), widget=forms.MultipleHiddenInput)
|
pk = forms.ModelMultipleChoiceField(queryset=Site.objects.all(), widget=forms.MultipleHiddenInput)
|
||||||
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
tenant = forms.TypedChoiceField(choices=bulkedit_tenant_choices, coerce=int, required=False, label='Tenant')
|
||||||
|
|
||||||
|
|
||||||
def site_tenant_choices():
|
def site_tenant_choices():
|
||||||
@ -181,7 +191,7 @@ class RackBulkEditForm(forms.Form, BootstrapMixin):
|
|||||||
pk = forms.ModelMultipleChoiceField(queryset=Rack.objects.all(), widget=forms.MultipleHiddenInput)
|
pk = forms.ModelMultipleChoiceField(queryset=Rack.objects.all(), widget=forms.MultipleHiddenInput)
|
||||||
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False)
|
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False)
|
||||||
group = forms.ModelChoiceField(queryset=RackGroup.objects.all(), required=False)
|
group = forms.ModelChoiceField(queryset=RackGroup.objects.all(), required=False)
|
||||||
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False)
|
tenant = forms.TypedChoiceField(choices=bulkedit_tenant_choices, coerce=int, required=False, label='Tenant')
|
||||||
u_height = forms.IntegerField(required=False, label='Height (U)')
|
u_height = forms.IntegerField(required=False, label='Height (U)')
|
||||||
comments = CommentField()
|
comments = CommentField()
|
||||||
|
|
||||||
@ -538,21 +548,12 @@ class ChildDeviceImportForm(BulkImportForm, BootstrapMixin):
|
|||||||
csv = CSVDataField(csv_form=ChildDeviceFromCSVForm)
|
csv = CSVDataField(csv_form=ChildDeviceFromCSVForm)
|
||||||
|
|
||||||
|
|
||||||
def device_edit_platform_choices():
|
|
||||||
choices = [
|
|
||||||
(None, '---------'),
|
|
||||||
(0, 'None'),
|
|
||||||
]
|
|
||||||
choices += [(p.pk, p.name) for p in Platform.objects.all()]
|
|
||||||
return choices
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceBulkEditForm(forms.Form, BootstrapMixin):
|
class DeviceBulkEditForm(forms.Form, BootstrapMixin):
|
||||||
pk = forms.ModelMultipleChoiceField(queryset=Device.objects.all(), widget=forms.MultipleHiddenInput)
|
pk = forms.ModelMultipleChoiceField(queryset=Device.objects.all(), widget=forms.MultipleHiddenInput)
|
||||||
device_type = forms.ModelChoiceField(queryset=DeviceType.objects.all(), required=False, label='Type')
|
device_type = forms.ModelChoiceField(queryset=DeviceType.objects.all(), required=False, label='Type')
|
||||||
device_role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False, label='Role')
|
device_role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False, label='Role')
|
||||||
tenant = forms.ModelChoiceField(queryset=Tenant.objects.all(), required=False, label='Tenant')
|
tenant = forms.TypedChoiceField(choices=bulkedit_tenant_choices, coerce=int, required=False, label='Tenant')
|
||||||
platform = forms.TypedChoiceField(choices=device_edit_platform_choices, coerce=int, required=False,
|
platform = forms.TypedChoiceField(choices=bulkedit_platform_choices, coerce=int, required=False,
|
||||||
label='Platform')
|
label='Platform')
|
||||||
status = forms.ChoiceField(choices=FORM_STATUS_CHOICES, required=False, initial='', label='Status')
|
status = forms.ChoiceField(choices=FORM_STATUS_CHOICES, required=False, initial='', label='Status')
|
||||||
serial = forms.CharField(max_length=50, required=False, label='Serial Number')
|
serial = forms.CharField(max_length=50, required=False, label='Serial Number')
|
||||||
|
@ -122,9 +122,10 @@ class SiteBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
for field in ['tenant']:
|
if form.cleaned_data['tenant'] == 0:
|
||||||
if form.cleaned_data[field]:
|
fields_to_update['tenant'] = None
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
elif form.cleaned_data['tenant']:
|
||||||
|
fields_to_update['tenant'] = form.cleaned_data['tenant']
|
||||||
|
|
||||||
return self.cls.objects.filter(pk__in=pk_list).update(**fields_to_update)
|
return self.cls.objects.filter(pk__in=pk_list).update(**fields_to_update)
|
||||||
|
|
||||||
@ -220,6 +221,10 @@ class RackBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
|
if form.cleaned_data['tenant'] == 0:
|
||||||
|
fields_to_update['tenant'] = None
|
||||||
|
elif form.cleaned_data['tenant']:
|
||||||
|
fields_to_update['tenant'] = form.cleaned_data['tenant']
|
||||||
for field in ['site', 'group', 'tenant', 'u_height', 'comments']:
|
for field in ['site', 'group', 'tenant', 'u_height', 'comments']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
@ -645,10 +650,11 @@ class DeviceBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
if form.cleaned_data['platform'] == 0:
|
for field in ['tenant', 'platform']:
|
||||||
fields_to_update['platform'] = None
|
if form.cleaned_data[field] == 0:
|
||||||
elif form.cleaned_data['platform']:
|
fields_to_update[field] = None
|
||||||
fields_to_update['platform'] = form.cleaned_data['platform']
|
elif form.cleaned_data[field]:
|
||||||
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
if form.cleaned_data['status']:
|
if form.cleaned_data['status']:
|
||||||
status = form.cleaned_data['status']
|
status = form.cleaned_data['status']
|
||||||
fields_to_update['status'] = True if status == 'True' else False
|
fields_to_update['status'] = True if status == 'True' else False
|
||||||
|
@ -4,6 +4,7 @@ from django import forms
|
|||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
|
|
||||||
from dcim.models import Site, Device, Interface
|
from dcim.models import Site, Device, Interface
|
||||||
|
from tenancy.forms import bulkedit_tenant_choices
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms import BootstrapMixin, APISelect, Livesearch, CSVDataField, BulkImportForm, SlugField
|
from utilities.forms import BootstrapMixin, APISelect, Livesearch, CSVDataField, BulkImportForm, SlugField
|
||||||
|
|
||||||
@ -17,6 +18,9 @@ FORM_VLAN_STATUS_CHOICES = (('', '---------'),) + VLAN_STATUS_CHOICES
|
|||||||
|
|
||||||
|
|
||||||
def bulkedit_vrf_choices():
|
def bulkedit_vrf_choices():
|
||||||
|
"""
|
||||||
|
Include an option to assign the object to the global table.
|
||||||
|
"""
|
||||||
choices = [
|
choices = [
|
||||||
(None, '---------'),
|
(None, '---------'),
|
||||||
(0, 'Global'),
|
(0, 'Global'),
|
||||||
@ -25,15 +29,6 @@ def bulkedit_vrf_choices():
|
|||||||
return choices
|
return choices
|
||||||
|
|
||||||
|
|
||||||
def bulkedit_tenant_choices():
|
|
||||||
choices = [
|
|
||||||
(None, '---------'),
|
|
||||||
(0, 'None'),
|
|
||||||
]
|
|
||||||
choices += [(t.pk, t.name) for t in Tenant.objects.all()]
|
|
||||||
return choices
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# VRFs
|
# VRFs
|
||||||
#
|
#
|
||||||
|
@ -86,7 +86,11 @@ class VRFBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
for field in ['tenant', 'description']:
|
if form.cleaned_data['tenant'] == 0:
|
||||||
|
fields_to_update['tenant'] = None
|
||||||
|
elif form.cleaned_data['tenant']:
|
||||||
|
fields_to_update['tenant'] = form.cleaned_data['tenant']
|
||||||
|
for field in ['description']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
|
|
||||||
@ -338,10 +342,11 @@ class PrefixBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
if form.cleaned_data['vrf'] == 0:
|
for field in ['vrf', 'tenant']:
|
||||||
fields_to_update['vrf'] = None
|
if form.cleaned_data[field] == 0:
|
||||||
elif form.cleaned_data['vrf']:
|
fields_to_update[field] = None
|
||||||
fields_to_update['vrf'] = form.cleaned_data['vrf']
|
elif form.cleaned_data[field]:
|
||||||
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
for field in ['site', 'status', 'role', 'description']:
|
for field in ['site', 'status', 'role', 'description']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
@ -462,10 +467,11 @@ class IPAddressBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
if form.cleaned_data['vrf'] == 0:
|
for field in ['vrf', 'tenant']:
|
||||||
fields_to_update['vrf'] = None
|
if form.cleaned_data[field] == 0:
|
||||||
elif form.cleaned_data['vrf']:
|
fields_to_update[field] = None
|
||||||
fields_to_update['vrf'] = form.cleaned_data['vrf']
|
elif form.cleaned_data[field]:
|
||||||
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
for field in ['description']:
|
for field in ['description']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
@ -560,7 +566,11 @@ class VLANBulkEditView(PermissionRequiredMixin, BulkEditView):
|
|||||||
def update_objects(self, pk_list, form):
|
def update_objects(self, pk_list, form):
|
||||||
|
|
||||||
fields_to_update = {}
|
fields_to_update = {}
|
||||||
for field in ['site', 'group', 'tenant', 'status', 'role', 'description']:
|
if form.cleaned_data['tenant'] == 0:
|
||||||
|
fields_to_update['tenant'] = None
|
||||||
|
elif form.cleaned_data['tenant']:
|
||||||
|
fields_to_update['tenant'] = form.cleaned_data['tenant']
|
||||||
|
for field in ['site', 'group', 'status', 'role', 'description']:
|
||||||
if form.cleaned_data[field]:
|
if form.cleaned_data[field]:
|
||||||
fields_to_update[field] = form.cleaned_data[field]
|
fields_to_update[field] = form.cleaned_data[field]
|
||||||
|
|
||||||
|
@ -8,6 +8,18 @@ from utilities.forms import (
|
|||||||
from .models import Tenant, TenantGroup
|
from .models import Tenant, TenantGroup
|
||||||
|
|
||||||
|
|
||||||
|
def bulkedit_tenant_choices():
|
||||||
|
"""
|
||||||
|
Include an option to remove the currently assigned Tenant from an object.
|
||||||
|
"""
|
||||||
|
choices = [
|
||||||
|
(None, '---------'),
|
||||||
|
(0, 'None'),
|
||||||
|
]
|
||||||
|
choices += [(t.pk, t.name) for t in Tenant.objects.all()]
|
||||||
|
return choices
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tenant groups
|
# Tenant groups
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user