mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Initial push to public repo
This commit is contained in:
29
netbox/utilities/error_handlers.py
Normal file
29
netbox/utilities/error_handlers.py
Normal file
@ -0,0 +1,29 @@
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
def handle_protectederror(obj, request, e):
|
||||
"""
|
||||
Generate a user-friendly error message in response to a ProtectedError exception.
|
||||
"""
|
||||
dependent_objects = e[1]
|
||||
try:
|
||||
dep_class = dependent_objects[0]._meta.verbose_name_plural
|
||||
except IndexError:
|
||||
raise e
|
||||
|
||||
# Handle multiple triggering objects
|
||||
if type(obj) in (list, tuple):
|
||||
messages.error(request, "Unable to delete the requested {}. The following dependent {} were found: {}".format(
|
||||
obj[0]._meta.verbose_name_plural,
|
||||
dep_class,
|
||||
', '.join([str(o) for o in dependent_objects])
|
||||
))
|
||||
|
||||
# Handle a single triggering object
|
||||
else:
|
||||
messages.error(request, "Unable to delete {} {}. The following dependent {} were found: {}".format(
|
||||
obj._meta.verbose_name,
|
||||
obj,
|
||||
dep_class,
|
||||
', '.join([str(o) for o in dependent_objects])
|
||||
))
|
Reference in New Issue
Block a user