Used getattr() to simplify contrib.messages.api.

This commit is contained in:
Curtis Maloney 2015-09-26 20:03:42 -04:00 committed by Tim Graham
parent a3a6def867
commit 87630bc304
1 changed files with 2 additions and 2 deletions

View File

@ -33,7 +33,7 @@ def get_messages(request):
Returns the message storage on the request if it exists, otherwise returns Returns the message storage on the request if it exists, otherwise returns
an empty list. an empty list.
""" """
return request._messages if hasattr(request, '_messages') else [] return getattr(request, '_messages', [])
def get_level(request): def get_level(request):
@ -43,7 +43,7 @@ def get_level(request):
The default level is the ``MESSAGE_LEVEL`` setting. If this is not found, The default level is the ``MESSAGE_LEVEL`` setting. If this is not found,
the ``INFO`` level is used. the ``INFO`` level is used.
""" """
storage = request._messages if hasattr(request, '_messages') else default_storage(request) storage = getattr(request, '_messages', default_storage(request))
return storage.level return storage.level