Ticket #2548: session_middleware.diff
File session_middleware.diff, 2.1 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): … … 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 max_age = request.session.expires 110 delta_yield = datetime.datetime.now() + datetime.timedelta(seconds=max_age) 111 expires = datetime.datetime.strftime(delta_yield, "%a, %d-%b-%Y %H:%M:%S GMT") 101 112 new_session = Session.objects.save(session_key, request.session._session, 102 d atetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE))113 delta_yield) 103 114 response.set_cookie(settings.SESSION_COOKIE_NAME, session_key, 104 115 max_age=max_age, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, 105 116 secure=settings.SESSION_COOKIE_SECURE or None)