mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-02 05:46:25 -06:00
Move validation to ensure all renames are eligible
This commit is contained in:
parent
75b0bea22b
commit
ec3a7f3bcb
@ -2122,17 +2122,6 @@ class DeviceBulkRenameView(generic.BulkRenameView):
|
||||
filterset = filtersets.DeviceFilterSet
|
||||
table = tables.DeviceTable
|
||||
|
||||
def _rename_objects(self, form, selected_objects):
|
||||
# Check devices for any unnamed devices and enforce requirements on the renaming of devices
|
||||
for obj in selected_objects:
|
||||
if not form.cleaned_data['use_regex'] and not obj.name:
|
||||
from django.core.exceptions import ValidationError
|
||||
raise ValidationError({
|
||||
'use_regex': 'You must use regex to rename a unnamed device and must pass device uniqueness checks'
|
||||
})
|
||||
|
||||
super()._rename_objects(form, selected_objects)
|
||||
|
||||
|
||||
@register_model_view(Device, 'contacts')
|
||||
class DeviceContactsView(ObjectContactsView):
|
||||
|
@ -727,6 +727,11 @@ class BulkRenameView(GetReturnURLMixin, BaseMultiObjectView):
|
||||
renamed_pks = []
|
||||
|
||||
for obj in selected_objects:
|
||||
# Validate that the rename will be successful and not trigger an error
|
||||
if not form.cleaned_data['use_regex'] and not obj.name:
|
||||
raise ValidationError({
|
||||
'use_regex': 'You must use regex to rename and must pass uniqueness checks'
|
||||
})
|
||||
|
||||
# Take a snapshot of change-logged models
|
||||
if hasattr(obj, 'snapshot'):
|
||||
|
Loading…
Reference in New Issue
Block a user