Ticket #15500: add_support_for_cookie_expiry_setting.patch
File add_support_for_cookie_expiry_setting.patch, 2.4 KB (added by , 14 years ago) |
---|
-
django/contrib/sessions/backends/base.py
3 3 import random 4 4 import sys 5 5 import time 6 from calendar import timegm 6 7 from datetime import datetime, timedelta 7 8 try: 8 9 import cPickle as pickle … … 197 198 198 199 _session = property(_get_session) 199 200 201 def _get_expiry_setting(self): 202 """ 203 Returns seconds until the cookie expires. Gets this value from either 204 SESSION_COOKIE_AGE or SESSION_COOKIE_EXPIRY_UTC. 205 """ 206 # If SESSION_COOKIE_EXPIRY_UTC is set by the user, use it. 207 # otherwise return the default: SESSION_COOKIE_AGE. 208 if not hasattr(settings, 'SESSION_COOKIE_EXPIRY_UTC'): 209 return settings.SESSION_COOKIE_AGE 210 else: 211 # Return the difference between the expiration date in UTC and 212 # the current unix time rounded down to seconds 213 return timegm(time.strptime(settings.SESSION_COOKIE_EXPIRY_UTC, 214 "%Y-%m-%d %H:%M:%S")) - int(time.time()) 215 200 216 def get_expiry_age(self): 201 217 """Get the number of seconds until the session expires.""" 202 218 expiry = self.get('_session_expiry') 203 219 if not expiry: # Checks both None and 0 cases 204 return se ttings.SESSION_COOKIE_AGE220 return self._get_expiry_setting() 205 221 if not isinstance(expiry, datetime): 206 222 return expiry 207 223 delta = expiry - datetime.now() … … 213 229 if isinstance(expiry, datetime): 214 230 return expiry 215 231 if not expiry: # Checks both None and 0 cases 216 expiry = se ttings.SESSION_COOKIE_AGE232 expiry = self._get_expiry_setting() 217 233 return datetime.now() + timedelta(seconds=expiry) 218 234 235 219 236 def set_expiry(self, value): 220 237 """ 221 238 Sets a custom expiration for the session. ``value`` can be an integer, -
django/contrib/sessions/backends/cached_db.py
39 39 """ 40 40 self.clear() 41 41 self.delete(self.session_key) 42 self.create() 43 No newline at end of file 42 self.create()