Ticket #832: sessions.diff

File sessions.diff, 2.2 KB (added by Esaj, 10 years ago)

Add a SESSION_COOKIE_PERSIST setting

  • django/conf/global_settings.py

     
    196196SESSION_COOKIE_NAME = 'hotclub'           # Cookie name. This can be whatever you want.
    197197SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks).
    198198SESSION_COOKIE_DOMAIN = None              # A string like ".lawrence.com", or None for standard domain cookie.
     199SESSION_COOKIE_PERSIST = True             # Whether session cookies persist across browser sessions.
    199200SESSION_SAVE_EVERY_REQUEST = False        # Whether to save the session data on every request.
    200201
    201202#########
  • django/middleware/sessions.py

     
    1 from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN, SESSION_SAVE_EVERY_REQUEST
     1from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN, SESSION_SAVE_EVERY_REQUEST, SESSION_COOKIE_PERSIST
    22from django.models.core import sessions
    33from django.utils.cache import patch_vary_headers
    44import datetime
     
    7171            session_key = request.session.session_key or sessions.get_new_session_key()
    7272            new_session = sessions.save(session_key, request.session._session,
    7373                datetime.datetime.now() + datetime.timedelta(seconds=SESSION_COOKIE_AGE))
    74             expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
     74            if SESSION_COOKIE_PERSIST:
     75                expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
     76            else:
     77                expires = None
    7578            response.set_cookie(SESSION_COOKIE_NAME, session_key,
    7679                max_age=SESSION_COOKIE_AGE, expires=expires, domain=SESSION_COOKIE_DOMAIN)
    7780        return response
Back to Top