i have django's @login_required
decorator test whether particular field on user has been set other none. (the added field has null = true , default of none.)
newly created user objects indeed have value of none field, obvious change @login_required
has made no discernible difference in behavior (i restarted gunicorn ensure fresh read). @login_required
views rendered if user authenticated, if added field none.
the present, changed @login_required
is:
def login_required(function=none, redirect_field_name=redirect_field_name): """ decorator views checks user logged in, redirecting log-in page if necessary. """ actual_decorator = user_passes_test( lambda u: u.foo != none, redirect_field_name=redirect_field_name ) if function: return actual_decorator(function) return actual_decorator
the original lambda on u.is_authenticated()
.
i see code, have encountered user_passes_test , in fact should use instead of modifying source code of login_required directly.
user_passes_test() takes required argument: callable takes user object , returns true if user allowed view page. note user_passes_test() not automatically check user not anonymous.
you create function ensures conditions met. makes sure stays inside code base (an update django not break app) , makes easier debug.
your test function might be.
def is_foo(user): if user.is_authenticated() , user.foo : return true