mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #5020: Correct handling of dependent objects during bulk deletion
This commit is contained in:
@ -3,18 +3,19 @@ from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
|
||||
def handle_protectederror(obj, request, e):
|
||||
def handle_protectederror(obj_list, request, e):
|
||||
"""
|
||||
Generate a user-friendly error message in response to a ProtectedError exception.
|
||||
"""
|
||||
protected_objects = list(e.protected_objects)
|
||||
err_message = f"Unable to delete {obj._meta.verbose_name} <strong>{obj}</strong>. " \
|
||||
f"{len(protected_objects)} dependent objects were found: "
|
||||
protected_count = len(protected_objects) if len(protected_objects) <= 50 else 'More than 50'
|
||||
err_message = f"Unable to delete <strong>{', '.join(str(obj) for obj in obj_list)}</strong>. " \
|
||||
f"{protected_count} dependent objects were found: "
|
||||
|
||||
# Append dependent objects to error message
|
||||
dependent_objects = []
|
||||
for dependent in protected_objects:
|
||||
if hasattr(obj, 'get_absolute_url'):
|
||||
for dependent in protected_objects[:50]:
|
||||
if hasattr(dependent, 'get_absolute_url'):
|
||||
dependent_objects.append(f'<a href="{dependent.get_absolute_url()}">{escape(dependent)}</a>')
|
||||
else:
|
||||
dependent_objects.append(str(dependent))
|
||||
|
Reference in New Issue
Block a user