Add Django-1.2.1
[frozenviper.git] / Django-1.2.1 / build / lib.linux-i686-2.6 / django / contrib / messages / middleware.py
bloba84dc6cb11489a812657537a52ec42718e673a88
1 from django.conf import settings
2 from django.contrib.messages.storage import default_storage
5 class MessageMiddleware(object):
6 """
7 Middleware that handles temporary messages.
8 """
10 def process_request(self, request):
11 request._messages = default_storage(request)
13 def process_response(self, request, response):
14 """
15 Updates the storage backend (i.e., saves the messages).
17 If not all messages could not be stored and ``DEBUG`` is ``True``, a
18 ``ValueError`` is raised.
19 """
20 # A higher middleware layer may return a request which does not contain
21 # messages storage, so make no assumption that it will be there.
22 if hasattr(request, '_messages'):
23 unstored_messages = request._messages.update(response)
24 if unstored_messages and settings.DEBUG:
25 raise ValueError('Not all temporary messages could be stored.')
26 return response