(
    func: Callable[[WSGIRequest], Optional[HttpResponse]]
)
return wraps(func)(_decorator)
A decorator that stores the last access for every connected ip
    so the number of active users can be determined.
A decorator that stores the last access for every connected ip
    so the number of active users can be determined.
A decorator that stores the last access for every connected ip so the number of active users can be determined .
def tracked(
    func: Callable[[WSGIRequest], Optional[HttpResponse]]
) -> Callable[[WSGIRequest], HttpResponse]:
    """A decorator that stores the last access for every connected ip
    so the number of active users can be determined."""

    def _decorator(request: WSGIRequest) -> HttpResponse:
        # create a sessions if none exists (necessary for anonymous users)
        if not request.session or not request.session.session_key:
            request.session.save()

        request_ip = get_client_ip(request)
        last_requests = redis.get("last_requests")
        last_requests[request_ip] = time.time()
        redis.set("last_requests", last_requests)

        def check():
            active = redis.get("active_requests")
            if active > 0:
                leds.enable_act_led()
            else:
                leds.disable_act_led()

        redis.incr("active_requests")
        check()
        response = func(request)
        redis.decr("active_requests")
        check()

        return response

    return wraps(func)(_decorator)
def tracked ( func : Callable [ [ WSGIRequest ] , Optional [ HttpResponse ] ] ) -> Callable [ [ WSGIRequest ] , HttpResponse ] : def _decorator ( request : WSGIRequest ) -> HttpResponse : # create a sessions if none exists (necessary for anonymous users) if not request . session or not request . session . session_key : request . session . save ( ) request_ip = get_client_ip ( request ) last_requests = redis . get ( "last_requests" ) last_requests [ request_ip ] = time . time ( ) redis . set ( "last_requests" , last_requests ) def check ( ) : active = redis . get ( "active_requests" ) if active > 0 : leds . enable_act_led ( ) else : leds . disable_act_led ( ) redis . incr ( "active_requests" ) check ( ) response = func ( request ) redis . decr ( "active_requests" ) check ( ) return response return wraps ( func ) ( _decorator )