I need some views that the login_required is controlled via a setting, some deployments of the code are open and some are closed (Different sites).
So I figured I could just write a quick decorator of my own and have it check the setting before then calling login_required. After trouble with that, I just took the entire login_required decorator code put it in my app/decoratores.py and called it, login_required_by_setting just to see that work.
def login_required_by_setting(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None):
"""
Decorator for views that checks that the user is logged in, redirecting
to the log-in page if necessary.
"""
actual_decorator = user_passes_test(
lambda u: u.is_authenticated,
login_url=login_url,
redirect_field_name=redirect_field_name
)
if function:
return actual_decorator(function)
return actual_decorator
But when I add that decorator to my view it lets me in when I'm not logged in,
but once I change it back to @login_required it works as expected.
Any ideas where to look, im at a loss.
Dylan