Skip to content

Instantly share code, notes, and snippets.

@snavruzov
Forked from dryan/InactivityLogout.py
Created August 18, 2021 12:44
Show Gist options
  • Select an option

  • Save snavruzov/8b3673eb07fe9bf90a3e9215b13e5e1f to your computer and use it in GitHub Desktop.

Select an option

Save snavruzov/8b3673eb07fe9bf90a3e9215b13e5e1f to your computer and use it in GitHub Desktop.

Revisions

  1. @dryan dryan created this gist Dec 18, 2009.
    8 changes: 8 additions & 0 deletions InactivityLogout.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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