Fixed #6087 -- Added setdefault() support to the Session object. Thanks, Ben
Slavin. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6831 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f610269006
commit
49da9ab57e
|
@ -51,6 +51,14 @@ class SessionBase(object):
|
||||||
self.modified = self.modified or key in self._session
|
self.modified = self.modified or key in self._session
|
||||||
return self._session.pop(key, *args)
|
return self._session.pop(key, *args)
|
||||||
|
|
||||||
|
def setdefault(self, key, value):
|
||||||
|
if key in self._session:
|
||||||
|
return self._session[key]
|
||||||
|
else:
|
||||||
|
self.modified = True
|
||||||
|
self._session[key] = value
|
||||||
|
return value
|
||||||
|
|
||||||
def set_test_cookie(self):
|
def set_test_cookie(self):
|
||||||
self[self.TEST_COOKIE_NAME] = self.TEST_COOKIE_VALUE
|
self[self.TEST_COOKIE_NAME] = self.TEST_COOKIE_VALUE
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,11 @@ False
|
||||||
>>> s.accessed, s.modified
|
>>> s.accessed, s.modified
|
||||||
(True, False)
|
(True, False)
|
||||||
|
|
||||||
|
>>> s.setdefault('foo', 'bar')
|
||||||
|
'bar'
|
||||||
|
>>> s.setdefault('foo', 'baz')
|
||||||
|
'bar'
|
||||||
|
|
||||||
>>> s.accessed = False # Reset the accessed flag
|
>>> s.accessed = False # Reset the accessed flag
|
||||||
|
|
||||||
>>> s.pop('some key')
|
>>> s.pop('some key')
|
||||||
|
|
|
@ -99,6 +99,8 @@ It implements the following standard dictionary methods:
|
||||||
|
|
||||||
* ``items()``
|
* ``items()``
|
||||||
|
|
||||||
|
* ``setdefault()``
|
||||||
|
|
||||||
It also has these three methods:
|
It also has these three methods:
|
||||||
|
|
||||||
* ``set_test_cookie()``
|
* ``set_test_cookie()``
|
||||||
|
|
Loading…
Reference in New Issue