Ticket #2548: session_middleware.10.diff
File session_middleware.10.diff, 4.1 KB (added by , 17 years ago) |
---|
-
AUTHORS
229 229 Karen Tracey <graybark@bellsouth.net> 230 230 Makoto Tsuyuki <mtsuyuki@gmail.com> 231 231 tt@gurgle.no 232 Amit Upadhyay 232 Amit Upadhyay <http://www.amitu.com/blog/> 233 233 Geert Vanderkelen 234 234 viestards.lists@gmail.com 235 235 Milton Waddams -
django/contrib/sessions/middleware.py
48 48 def delete_test_cookie(self): 49 49 del self[TEST_COOKIE_NAME] 50 50 51 def set_life(self, val): 52 """ 53 sets the life of the session, irrespective of global settings. 54 val is in seconds. 55 """ 56 self["_expires_on"] = TILL_BROWSER_CLOSE 57 51 58 def _get_session(self): 52 59 # Lazily loads session from storage. 53 60 self.accessed = True … … 92 99 obj = Session.objects.get_new_session_object() 93 100 session_key = obj.session_key 94 101 95 if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE: 96 max_age = None 97 expires = None 98 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") 101 new_session = Session.objects.save(session_key, request.session._session, 102 datetime.datetime.now() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)) 103 response.set_cookie(settings.SESSION_COOKIE_NAME, session_key, 102 now = datetime.datetime.now() 103 delta_yield = now + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE) 104 if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE and not request.session.get("_expires_on"): 105 max_age = None 106 expires = None 107 else: 108 delta_yield = request.session.get("_expires_on", delta_yield) 109 max_age_timedelta = delta_yield - now 110 max_age = max_age_timedelta.days * 24 * 60 * 60 + max_age_timedelta.seconds 111 expires = datetime.datetime.strftime(delta_yield, "%a, %d-%b-%Y %H:%M:%S GMT") 112 Session.objects.save(session_key, request.session._session, delta_yield) 113 response.set_cookie( 114 settings.SESSION_COOKIE_NAME, session_key, 104 115 max_age=max_age, expires=expires, domain=settings.SESSION_COOKIE_DOMAIN, 105 secure=settings.SESSION_COOKIE_SECURE or None) 116 secure=settings.SESSION_COOKIE_SECURE or None 117 ) 106 118 return response -
docs/sessions.txt
58 58 59 59 * ``items()`` 60 60 61 It also has these threemethods:61 It also has these four methods: 62 62 63 63 * ``set_test_cookie()`` 64 64 Sets a test cookie to determine whether the user's browser supports … … 75 75 * ``delete_test_cookie()`` 76 76 Deletes the test cookie. Use this to clean up after yourself. 77 77 78 * ``set_life(val)`` 79 It takes an integer, number of seconds for which the session should be 80 valid. Calling set_life will overwrite the global/default session expiry 81 policy. See `browser-length sessions vs. persistent sessions` for 82 default session expiry policy. 83 78 84 You can edit ``request.session`` at any point in your view. You can edit it 79 85 multiple times. 80 86 … … 217 223 her browser. Use this if you want people to have to log in every time they open 218 224 a browser. 219 225 226 These settings are global defaults, and can be overwritten by explicitly calling 227 ``request.session.set_life()`` as described above. 228 220 229 Clearing the session table 221 230 ========================== 222 231