mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
utilities: move protectederror handling to modelviewset
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
from django.conf import settings
|
||||
from django.db import ProgrammingError
|
||||
from django.http import Http404, HttpResponseRedirect, JsonResponse
|
||||
from django.db.models import ProtectedError
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
|
||||
from .views import server_error
|
||||
@ -63,11 +62,6 @@ class ExceptionHandlingMiddleware(object):
|
||||
if isinstance(exception, Http404):
|
||||
return
|
||||
|
||||
elif isinstance(exception, ProtectedError):
|
||||
models = '\n'.join('- {} ({})'.format(o, o._meta) for o in exception.protected_objects.all())
|
||||
msg = 'You tried deleting a model that is protected by:\n{}'.format(models)
|
||||
return JsonResponse({'detail': msg}, status=403)
|
||||
|
||||
# Determine the type of exception. If it's a common issue, return a custom error page with instructions.
|
||||
custom_template = None
|
||||
if isinstance(exception, ProgrammingError):
|
||||
|
Reference in New Issue
Block a user