Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #6087 -- Added setdefault() support to the Session object. Than…

…ks, Ben

Slavin.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6831 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 49da9ab57e61e8b6d14ea72b5256555cb5c41cb5 1 parent f610269
@malcolmt malcolmt authored
View
8 django/contrib/sessions/backends/base.py
@@ -51,6 +51,14 @@ def pop(self, key, *args):
self.modified = self.modified or key in self._session
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):
self[self.TEST_COOKIE_NAME] = self.TEST_COOKIE_VALUE
View
5 django/contrib/sessions/tests.py
@@ -66,6 +66,11 @@
>>> s.accessed, s.modified
(True, False)
+>>> s.setdefault('foo', 'bar')
+'bar'
+>>> s.setdefault('foo', 'baz')
+'bar'
+
>>> s.accessed = False # Reset the accessed flag
>>> s.pop('some key')
View
2  docs/sessions.txt
@@ -99,6 +99,8 @@ It implements the following standard dictionary methods:
* ``items()``
+ * ``setdefault()``
+
It also has these three methods:
* ``set_test_cookie()``
Please sign in to comment.
Something went wrong with that request. Please try again.