Example #1
0
def loginout_required(function=None, redirect_field_name='index', 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: AnonymousUser.__instancecheck__(u),
        login_url='index',
        redirect_field_name='index',
    )
    if function:
        return actual_decorator(function)
    return actual_decorator