From c56beed24061bf94b67be21806fa654a1e180b5f Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Tue, 12 Jan 2010 02:41:57 +0000 Subject: 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 --- docs/ref/contrib/messages.txt | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'docs') 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. -- cgit v1.3