Ticket #2548: session_middleware.2.diff
File session_middleware.2.diff, 2.5 KB (added by , 17 years ago) |
---|
-
contrib/sessions/middleware.py
12 12 self.session_key = session_key 13 13 self.accessed = False 14 14 self.modified = False 15 self.expires_time = False 15 16 16 17 def __contains__(self, key): 17 18 return key in self._session … … 48 49 def delete_test_cookie(self): 49 50 del self[TEST_COOKIE_NAME] 50 51 52 def set_expires(self, val): 53 self.expires_time = val 54 self.modified = True 55 56 def get_expires(self): 57 return self.expires_time or settings.SESSION_COOKIE_AGE 58 59 51 60 def _get_session(self): 52 61 # Lazily loads session from storage. 53 62 self.accessed = True … … 69 78 return self._session_cache 70 79 71 80 _session = property(_get_session) 81 expires = property(get_expires, set_expires) 72 82 73 83 class SessionMiddleware(object): 74 84 def process_request(self, request): … … 92 102 obj = Session.objects.get_new_session_object() 93 103 session_key = obj.session_key 94 104 95 if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE :105 if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE and not request.session.expires_time: 96 106 max_age = None 107 delta_yield = datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE) 97 108 expires = None 98 109 else: 99 max_age = settings.SESSION_COOKIE_AGE 100 expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT") 110 max_age = request.session.expires 111 delta_yield = datetime.datetime.now() + datetime.timedelta(seconds=max_age) 112 expires = datetime.datetime.strftime(delta_yield, "%a, %d-%b-%Y %H:%M:%S GMT") 101 113 new_session = Session.objects.save(session_key, request.session._session, 102 d atetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))114 delta_yield) 103 115 response.set_cookie(settings.SESSION_COOKIE_NAME, session_key, 104 116 max_age=max_age, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, 105 117 secure=settings.SESSION_COOKIE_SECURE or None)