diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-14 03:57:30 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-14 03:57:30 +0000 |
| commit | 31ec68c5d939ee63852709163750a0516aaa2619 (patch) | |
| tree | 3d2b2a6eb8d0b2817a96e8fa564aed7c200d3a0c | |
| parent | af7b6475ca6ab12df6b91beae1bb5b1c29a5782b (diff) | |
Added a clear() method to sessions. Patch from mrts. Refs #7515.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8341 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/contrib/sessions/backends/base.py | 4 | ||||
| -rw-r--r-- | django/contrib/sessions/tests.py | 10 | ||||
| -rw-r--r-- | docs/sessions.txt | 4 |
3 files changed, 16 insertions, 2 deletions
diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py index ed1311764c..a267eb1875 100644 --- a/django/contrib/sessions/backends/base.py +++ b/django/contrib/sessions/backends/base.py @@ -120,6 +120,10 @@ class SessionBase(object): 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. diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py index a1bc6799fa..afb9b3dfd3 100644 --- a/django/contrib/sessions/tests.py +++ b/django/contrib/sessions/tests.py @@ -147,7 +147,15 @@ True >>> 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 # diff --git a/docs/sessions.txt b/docs/sessions.txt index b5c9ba8394..39df04ad71 100644 --- a/docs/sessions.txt +++ b/docs/sessions.txt @@ -77,7 +77,7 @@ When ``SessionMiddleware`` is activated, each ``HttpRequest`` object -- the 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)`` @@ -106,6 +106,8 @@ It implements the following standard dictionary methods: * ``setdefault()`` (**New in Django development version**) + * ``clear()`` (**New in Django development version**) + It also has these methods: * ``set_test_cookie()`` |
