Ticket #2548: sessions_set_get_expire_v2.diff
File sessions_set_get_expire_v2.diff, 2.1 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_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 delta_yield = datetime.datetime.now() + datetime.timedelta(seconds=max_age) 97 expires = datetime.datetime.strftime(delta_yield, "%a, %d-%b-%Y %H:%M:%S GMT") 88 98 new_session = Session.objects.save(session_key, request.session._session, 89 d atetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))99 delta_yield) 90 100 response.set_cookie(settings.SESSION_COOKIE_NAME, session_key, 91 101 max_age=max_age, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, 92 102 secure=settings.SESSION_COOKIE_SECURE or None)