RefreshSessionMiddleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.conf import settings

REFRESH_AGE = getattr(settings, 'SESSION_COOKIE_REFRESH_AGE',
        int(settings.SESSION_COOKIE_AGE / 2))

class RefreshSessionMiddleware(object):
    """
    This middleware automatically refreshes the session after some time
    (default: settings.SESSION_COOKIE_AGE / 2).
    """
    def process_request(self, request):
        assert hasattr(request, 'session'), "RefreshSessionMiddleware " \
                "requires session middleware to be installed. Edit your " \
                "MIDDLEWARE_CLASSES setting to insert " \
                "'django.contrib.sessions.middleware.SessionMiddleware'."
        if request.session.get_expiry_age() < REFRESH_AGE:
            request.session.modified = True
        return None

More like this

  1. Middleware for using HttpOnly session cookie (including monkey patching for support for Python <2.6) by chrj 3 years, 11 months ago
  2. CurrentSessionIDMiddleware by troolee 3 years, 9 months ago
  3. HammeringMiddleware by pandoodl 3 years, 1 month ago
  4. Keep Me Logged In for Django by krvss 3 years, 2 months ago
  5. StrictAuthentication - Auto log-out inactive users by yeago 5 years, 6 months ago

Comments

robharvey (on October 25, 2008):

I think you'd want to ensure get_expiry_age() is >= 0 as well.

#

(Forgotten your password?)