middleware.py 329 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
class RecordActivityMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        response = self.get_response(request)
        if hasattr(request, "user") and request.user.is_authenticated:
            request.user.record_activity()
        return response