Views¶
- class core.views.CustomSnippetDeleteView(**kwargs)¶
A view that extends Wagtail’s
DeleteViewfor handlingRestrictedErrorexceptions.- form_valid(form)¶
Overrides the default
form_validmethod so that RestrictedErrors can be handled. These errors occur whenon_deleteis set toRESTRICTand 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 (whendebug = False) or a stack trace (whendebug = 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
RestrictedErroris found, stay on page. If deletion is successful, redirect tosuccess_url.- Return type:
HttpResponseRedirect
- _handle_restricted_error(error: RestrictedError)¶
Handles
RestrictedErrorexceptions 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
SnippetViewSetthat uses theCustomSnippetDeleteViewfor handlingRestrictedErrorexceptions.