Code

Ticket #7515: session_clear-with_docs.diff

File session_clear-with_docs.diff, 1.5 KB (added by anonymous, 6 years ago)
Line 
1Index: django/contrib/sessions/tests.py
2===================================================================
3--- django/contrib/sessions/tests.py    (revision 7715)
4+++ django/contrib/sessions/tests.py    (working copy)
5@@ -147,6 +147,15 @@
6 >>> list(i)
7 [('x', 1)]
8 
9+# test .clear()
10+>>> s.modified = s.accessed = False
11+>>> s.items()
12+[('x', 1)]
13+>>> s.clear()
14+>>> s.items()
15+[]
16+>>> s.accessed, s.modified
17+(True, True)
18 
19 
20 #########################
21Index: django/contrib/sessions/backends/base.py
22===================================================================
23--- django/contrib/sessions/backends/base.py    (revision 7715)
24+++ django/contrib/sessions/backends/base.py    (working copy)
25@@ -52,6 +52,10 @@
26         self.modified = self.modified or key in self._session
27         return self._session.pop(key, *args)
28 
29+    def clear(self):
30+        self._session.clear()
31+        self.modified = True
32+
33     def setdefault(self, key, value):
34         if key in self._session:
35             return self._session[key]
36Index: docs/sessions.txt
37===================================================================
38--- docs/sessions.txt   (revision 7715)
39+++ docs/sessions.txt   (working copy)
40@@ -106,6 +106,11 @@
41 
42     * ``setdefault()`` (**New in Django development version**)
43 
44+    * ``clear()`` (**New in Django development version**)
45+
46+      This reliably clears all session data, in result an empty session is
47+      saved to the session store.
48+
49 It also has these methods:
50 
51     * ``set_test_cookie()``