Ticket #2548: session_middleware.3.diff
File session_middleware.3.diff, 2.3 KB (added by , 17 years ago) |
---|
-
contrib/sessions/middleware.py
48 48 def delete_test_cookie(self): 49 49 del self[TEST_COOKIE_NAME] 50 50 51 def set_expires(self, val): 52 self["_expires_on"] = datetime.datetime.now() + datetime.timedelta(seconds=val) 53 54 def get_expires(self): 55 return self.get("_expires_on", None) 56 57 51 58 def _get_session(self): 52 59 # Lazily loads session from storage. 53 60 self.accessed = True … … 69 76 return self._session_cache 70 77 71 78 _session = property(_get_session) 79 expires = property(get_expires, set_expires) 72 80 73 81 class SessionMiddleware(object): 74 82 def process_request(self, request): … … 92 100 obj = Session.objects.get_new_session_object() 93 101 session_key = obj.session_key 94 102 95 if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE: 103 now = datetime.datetime.now() 104 delta_yield = now + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE) 105 if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE and not request.session.expires: 96 106 max_age = None 97 107 expires = None 98 108 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") 109 delta_yield = request.session.expires or delta_yield 110 max_age_timedelta = delta_yield - now 111 max_age = max_age_timedelta.days * 24 * 60 * 60 + max_age_timedelta.seconds 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)