human
Complete this python program:
def login_required(f=None, redirect=True):
assistant
#Here is the Python program you requested.

    """Like Django\s login_required, but with to= instead of next=.
    If redirect=False then we return 401 instead of redirecting to the
    login page.  That\s nice for ajax views.
    """
    def decorator(func):
        @functools.wraps(func)
        def wrapper(request, *args, **kw):
            if request.user.is_authenticated():
                return func(request, *args, **kw)
            elif redirect:
                return redirect_for_login(request)
            else:
                return http.HttpResponse(status=401)
        return wrapper
    if f:
        return decorator(f)
    else:
        return decorator