[Answer]-Django FormWizard and Permissions

1👍

You don’t have to decorate the view in the url conf. You can do so in your views.py,

protected_wizard_view = login_required(MyWizardView.as_view())

and then import protected_wizard_view in your urls.py.

(r'^wizard/', protected_wizard_view),

Another other option is to decorate the dispatch method, as described in the docs.

class MyWizardView(WizardView):

    @method_decorator(login_required)
    def dispatch(self, *args, **kwargs):
        return super(MyWizardView, self).dispatch(*args, **kwargs)

0👍

@Alasdair response is good, there’s also a great app that contains many helpers and mixins that you can use for Class Based View, take a look here.

Run pip install django-braces and you can use LoginRequiredMixin

from braces.views import LoginRequiredMixin

class MyWizardView(LoginRequiredMixin, WizardView):
    pass

There’s also mixins like PermissionRequiredMixin, MultiplePermissionsRequiredMixin, GroupRequiredMixin

👤Mounir

Leave a comment