Commits

mtre...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 5dbe07d

Added a clear() method to sessions. Patch from mrts. Refs #7515.

  • Participants
  • Parent commits 36bd321

Comments (0)

Files changed (3)

File django/contrib/sessions/backends/base.py

     def iteritems(self):
         return self._session.iteritems()
 
+    def clear(self):
+        self._session.clear()
+        self.modified = True
+
     def _get_new_session_key(self):
         "Returns session key that isn't being used."
         # The random module is seeded when this Apache child is created.

File django/contrib/sessions/tests.py

 >>> list(i)
 [('x', 1)]
 
- 
+# test .clear()
+>>> s.modified = s.accessed = False
+>>> s.items()
+[('x', 1)]
+>>> s.clear()
+>>> s.items()
+[]
+>>> s.accessed, s.modified
+(True, True)
 
 #########################
 # Custom session expiry #

File docs/sessions.txt

 first argument to any Django view function -- will have a ``session``
 attribute, which is a dictionary-like object. You can read it and write to it.
 
-It implements the following standard dictionary methods:
+A session object has the following standard dictionary methods:
 
     * ``__getitem__(key)``
 
 
     * ``setdefault()`` (**New in Django development version**)
 
+    * ``clear()`` (**New in Django development version**)
+
 It also has these methods:
 
     * ``set_test_cookie()``