Ticket #2548: sessions_set_get_expire.diff
File sessions_set_get_expire.diff, 2.2 KB (added by , 18 years ago) |
---|
-
django/contrib/sessions/middleware.py
10 10 def __init__(self, session_key): 11 11 self.session_key = session_key 12 12 self.modified = False 13 self.expires_time = False 13 14 14 15 def __contains__(self, key): 15 16 return key in self._session … … 43 44 def delete_test_cookie(self): 44 45 del self[TEST_COOKIE_NAME] 45 46 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 46 54 def _get_session(self): 47 55 # Lazily loads session from storage. 48 56 try: … … 63 71 return self._session_cache 64 72 65 73 _session = property(_get_session) 74 expires = property(get_expires, set_expires) 66 75 67 76 class SessionMiddleware(object): 68 77 def process_request(self, request): … … 83 92 max_age = None 84 93 expires = None 85 94 else: 86 max_age = settings.SESSION_COOKIE_AGE87 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") 88 97 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))) 90 99 response.set_cookie(settings.SESSION_COOKIE_NAME, session_key, 91 100 max_age=max_age, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, 92 101 secure=settings.SESSION_COOKIE_SECURE or None)