summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2010-01-12 02:41:57 +0000
committerLuke Plant <L.Plant.98@cantab.net>2010-01-12 02:41:57 +0000
commitc56beed24061bf94b67be21806fa654a1e180b5f (patch)
tree139b9701d841086d034cfd7473d3cef0671363a6 /docs
parent2f9853b2dc90f30317e0374396f08e3d142844d2 (diff)
Fixed #12575 - created a better interface for getting/setting the effective level of contrib.messages
Thanks Chris Beaven. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12207 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/messages.txt22
1 files changed, 15 insertions, 7 deletions
diff --git a/docs/ref/contrib/messages.txt b/docs/ref/contrib/messages.txt
index 7cfe4ae85a..554e70b1f2 100644
--- a/docs/ref/contrib/messages.txt
+++ b/docs/ref/contrib/messages.txt
@@ -137,8 +137,11 @@ Constant Purpose
``ERROR`` An action was **not** successful or some other failure occurred
=========== ========
-The `MESSAGE_LEVEL`_ setting can be used to change the minimum recorded
-level. Attempts to add messages of a level less than this will be ignored.
+The `MESSAGE_LEVEL`_ setting can be used to change the minimum recorded level
+(or it can be `changed per request`_). Attempts to add messages of a level less
+than this will be ignored.
+
+.. _`changed per request`: `Changing the minimum recorded level per-request`_
Message tags
------------
@@ -245,22 +248,27 @@ provide a mapping via the `MESSAGE_TAGS`_ setting.
Changing the minimum recorded level per-request
-----------------------------------------------
-The minimum recorded level can be set per request by changing the ``level``
-attribute of the messages storage instance::
+The minimum recorded level can be set per request via the ``set_level``
+method::
from django.contrib import messages
# Change the messages level to ensure the debug message is added.
- messages.get_messages(request).level = messages.DEBUG
+ messages.set_level(request, messages.DEBUG)
messages.debug(request, 'Test message...')
# In another request, record only messages with a level of WARNING and higher
- messages.get_messages(request).level = messages.WARNING
+ messages.set_level(request, messages.WARNING)
messages.success(request, 'Your profile was updated.') # ignored
messages.warning(request, 'Your account is about to expire.') # recorded
# Set the messages level back to default.
- messages.get_messages(request).level = None
+ messages.set_level(request, None)
+
+Similarly, the current effective level can be retrieved with ``get_level``::
+
+ from django.contrib import messages
+ current_level = messages.get_level(request)
For more information on how the minimum recorded level functions, see
`Message levels`_ above.