mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Enforce custom validators during bulk edit
This commit is contained in:
parent
0dcead40e8
commit
d592285b98
@ -86,14 +86,12 @@ class CustomValidator:
|
|||||||
if name in m2m_fields:
|
if name in m2m_fields:
|
||||||
if name in instance._m2m_values:
|
if name in instance._m2m_values:
|
||||||
return instance._m2m_values[name]
|
return instance._m2m_values[name]
|
||||||
elif instance.pk:
|
if instance.pk:
|
||||||
# TODO: Handle invalid attrs
|
|
||||||
return list(getattr(instance, name).all())
|
return list(getattr(instance, name).all())
|
||||||
else:
|
return []
|
||||||
return []
|
|
||||||
|
|
||||||
# Raise a ValidationError for unknown attributes
|
# Raise a ValidationError for unknown attributes
|
||||||
elif not hasattr(instance, name):
|
if not hasattr(instance, name):
|
||||||
raise ValidationError(_('Invalid attribute "{name}" for {model}').format(
|
raise ValidationError(_('Invalid attribute "{name}" for {model}').format(
|
||||||
name=name,
|
name=name,
|
||||||
model=instance.__class__.__name__
|
model=instance.__class__.__name__
|
||||||
|
@ -557,6 +557,14 @@ class BulkEditView(GetReturnURLMixin, BaseMultiObjectView):
|
|||||||
elif name in form.changed_data:
|
elif name in form.changed_data:
|
||||||
obj.custom_field_data[cf_name] = customfield.serialize(form.cleaned_data[name])
|
obj.custom_field_data[cf_name] = customfield.serialize(form.cleaned_data[name])
|
||||||
|
|
||||||
|
# Store M2M values for validation
|
||||||
|
obj._m2m_values = {}
|
||||||
|
for field in obj._meta.local_many_to_many:
|
||||||
|
if value := form.cleaned_data.get(field.name):
|
||||||
|
obj._m2m_values[field.name] = list(value)
|
||||||
|
elif field.name in nullified_fields:
|
||||||
|
obj._m2m_values[field.name] = []
|
||||||
|
|
||||||
obj.full_clean()
|
obj.full_clean()
|
||||||
obj.save()
|
obj.save()
|
||||||
updated_objects.append(obj)
|
updated_objects.append(obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user