Views

class core.views.CustomSnippetDeleteView(**kwargs)

A view that extends Wagtail’s DeleteView for handling RestrictedError exceptions.

form_valid(form)

Overrides the default form_valid method so that RestrictedErrors can be handled. These errors occur when on_delete is set to RESTRICT and the object that we’re trying to delete is referenced by another object (it’s foreign key is protected). Rather than show a 500 Internal Server Error (when debug = False) or a stack trace (when debug = True), we catch the error, stay on the page, and display it in a warning banner.

Raises:

PermissionDenied – If the object being deleted has a usage that is protected.

Returns:

If RestrictedError is found, stay on page. If deletion is successful, redirect to success_url.

Return type:

HttpResponseRedirect

_handle_restricted_error(error: RestrictedError)

Handles RestrictedError exceptions raised when trying to delete an object that is referenced by another object with a protected foreign key. Displays an error message in Wagtail’s warning banner, with each protected object linked to that object’s edit view in Wagtail).

Returns:

Redirect to the same page, with an error message in the banner.

Return type:

HttpResponseRedirect

class core.views.SnippetWithCustomDeleteViewSet(**kwargs)

A SnippetViewSet that uses the CustomSnippetDeleteView for handling RestrictedError exceptions.