staff_member_required doesn't work for FormWizard / __call__()
|Reported by:||Alpha1650||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The "staff_member_required" decorator doesn't work for FormWizard or in general for decorating methods as for example _ _call_ _(). That's because the decorator expects the first argument to be a request instance but with methods the first argument is self and the second argument is the request object.
The patch changes this by adding a check whether the object to be decorated is a function or a method. Then it decorates the appropriate way.
In order to decorate FormWizard's _ _call_ _() you have to do this:
from django.contrib.formtools.wizard import FormWizard from django.contrib.admin.views.decorators import staff_member_required class Wizard(FormWizard): # ... pass Wizard.__call__ = staff_member_required(Wizard.__call__)
I added my changes as a patch.
Change History (5)
Changed 6 years ago by anonymous
comment:1 follow-up: ↓ 2 Changed 6 years ago by Alex
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset