Pairs with django-neuralyzer, with wagtail support.
pip install wagtail-neuralyzer
Add wagtail_neuralyzer
to your INSTALLED_APP
:
INSTALLED_APP = [
...
"django_neuralyzer",
"wagtail_neuralyzer",
...
]
Add the NeuralyzeSnippetViewSetMixin
to your snippet class:
from wagtail_neuralyzer.views import NeuralyzeSnippetViewSetMixin
from wagtail_neuralyzer.views import NeuralyzeView
from my_app.neuralyzers import PersonNeuralyzer
# Create a new view that handle url and action as well as neuralyzer class
class OperatorNeuralyzeView(NeuralyzeView):
neuralyzer_class = OperatorNeuralyzer
# inherit NeuralyzeSnippetViewSetMixin to register new url and neuralyze view
class PersonSnippetViewSet(NeuralyzeSnippetViewSetMixin, SnippetViewSet):
model = Person
neuralyze_view_class = OperatorNeuralyzeView
...
and finally register the new action:
from wagtail import hooks
from wagtail_neuralyzer.menu_item import NeuralyzeMenuItem
@hooks.register("register_snippet_action_menu_item")
def register_anonymize_menu_item(model):
if model == Person:
return NeuralyzeMenuItem()
And Tada, your model should have an "Anonymize" action together with save/delete/publish/...
You can also add bulk action to the index view by registering wagtail hook
from wagtail import hooks
from wagtail_neuralyzer.action import NeuralyzeBulkAction
from my_app.models import Person
from my_app.neuralyzers import StudentNeuralyzer
@hooks.register("register_bulk_action")
class PersonNeuralyzerBulkAction(NeuralyzeBulkAction):
models = [Person] # specify model here
neuralyzer_class = PersonNeuralyzer # and neuralyzer to use here