I've got some methods which have attributes (to use .Net terminology). Something like.
#Example Usage
@RequireLoggedIn
def SomeAuthorisedFunction():
# ...
The attribute is defined as
def RequireLoggedIn(func):
func.AuthenticationRequired = True
return func
I can then check if this has been set using hasattr(view_func, 'AuthenticationRequired')
. What I'd like to do is something like this...
@RequireRole('Administrator')
def SomeAuthorisedFunction():
# ...
I've tried defining an attribute like this:
def RequireRole(func, Role):
func.RequiresRole = Role
return func
But @RequireRole('Administrator')
results in missing positional argument "Role"
and @RequireRole(Role='Administrator')
results in missing positional argument "func"
.
How can I specify properties for attributes?