Created
December 18, 2009 20:01
-
-
Save dryan/259723 to your computer and use it in GitHub Desktop.
Django middleware for extending session expiration on access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InactivityLogout(object): | |
def process_request( self, request ): | |
from datetime import datetime, timedelta | |
from django.conf import settings | |
COOKIE_AGE = getattr(settings, 'SESSION_COOKIE_AGE', 7200) | |
if datetime.now() – request.session.get_expiry_date() < timedelta(seconds = COOKIE_AGE): | |
request.session.set_expiry(datetime.now() + timedelta(seconds = COOKIE_AGE)) | |
return None # pass through |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment