Ticket #2548: sessions_set_get_expire.diff

File sessions_set_get_expire.diff, 2.2 KB (added by Tsume, 18 years ago)
  • django/contrib/sessions/middleware.py

     
    1010    def __init__(self, session_key):
    1111        self.session_key = session_key
    1212        self.modified = False
     13        self.expires_time = False
    1314
    1415    def __contains__(self, key):
    1516        return key in self._session
     
    4344    def delete_test_cookie(self):
    4445        del self[TEST_COOKIE_NAME]
    4546
     47    def set_expires(self, val):
     48        self.expires_time = val
     49        self.modified = True
     50
     51    def get_expires(self):
     52        return self.expires_time or settings.SESSION_COOKIE_AGE
     53
    4654    def _get_session(self):
    4755        # Lazily loads session from storage.
    4856        try:
     
    6371            return self._session_cache
    6472
    6573    _session = property(_get_session)
     74    expires = property(get_expires, set_expires)
    6675
    6776class SessionMiddleware(object):
    6877    def process_request(self, request):
     
    8392                    max_age = None
    8493                    expires = None
    8594                else:
    86                     max_age = settings.SESSION_COOKIE_AGE
    87                     expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
     95                    max_age = request.session.expires_time or settings.SESSION_COOKIE_AGE
     96                    expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=(request.session.expires_time or settings.SESSION_COOKIE_AGE)), "%a, %d-%b-%Y %H:%M:%S GMT")
    8897                new_session = Session.objects.save(session_key, request.session._session,
    89                     datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))
     98                    datetime.datetime.now() + datetime.timedelta(seconds=(request.session.expires_time or settings.SESSION_COOKIE_AGE)))
    9099                response.set_cookie(settings.SESSION_COOKIE_NAME, session_key,
    91100                    max_age=max_age, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN,
    92101                    secure=settings.SESSION_COOKIE_SECURE or None)
Back to Top