I want different functions to be executable only if the logged in user has the required permission level.
To make my life more complexly simply I want to use decorat
Your decorator should return a function that can replace do_x
or do_y
, not return the execution result of do_x
or do_y
You can modity you decorate as below:
def permission(permission_required):
def wrapper(func):
def inner():
setattr(func, 'permission_required', permission_required)
return func
return inner()
return wrapper
Of course, you have another brief solution:
def permission(permission_required):
def wrapper(func):
setattr(func, 'permission_required', permission_required)
return func
return wrapper