diff --git a/django/contrib/messages/api.py b/django/contrib/messages/api.py index 7a67e8b4b0..4b7d750a67 100644 --- a/django/contrib/messages/api.py +++ b/django/contrib/messages/api.py @@ -19,7 +19,7 @@ class MessageFailure(Exception): pass -def add_message(request, level, message, extra_tags="", fail_silently=False): +def add_message(request, level, message, extra_tags="", fail_silently=False, **kwargs): """ Attempt to add a message to the request using the 'messages' app. """ @@ -37,7 +37,7 @@ def add_message(request, level, message, extra_tags="", fail_silently=False): "django.contrib.messages.middleware.MessageMiddleware" ) else: - return messages.add(level, message, extra_tags) + return messages.add(level, message, extra_tags, **kwargs) def get_messages(request): @@ -72,7 +72,7 @@ def set_level(request, level): return True -def debug(request, message, extra_tags="", fail_silently=False): +def debug(request, message, extra_tags="", fail_silently=False, **kwargs): """Add a message with the ``DEBUG`` level.""" add_message( request, @@ -80,10 +80,11 @@ def debug(request, message, extra_tags="", fail_silently=False): message, extra_tags=extra_tags, fail_silently=fail_silently, + **kwargs, ) -def info(request, message, extra_tags="", fail_silently=False): +def info(request, message, extra_tags="", fail_silently=False, **kwargs): """Add a message with the ``INFO`` level.""" add_message( request, @@ -91,10 +92,11 @@ def info(request, message, extra_tags="", fail_silently=False): message, extra_tags=extra_tags, fail_silently=fail_silently, + **kwargs, ) -def success(request, message, extra_tags="", fail_silently=False): +def success(request, message, extra_tags="", fail_silently=False, **kwargs): """Add a message with the ``SUCCESS`` level.""" add_message( request, @@ -102,10 +104,11 @@ def success(request, message, extra_tags="", fail_silently=False): message, extra_tags=extra_tags, fail_silently=fail_silently, + **kwargs, ) -def warning(request, message, extra_tags="", fail_silently=False): +def warning(request, message, extra_tags="", fail_silently=False, **kwargs): """Add a message with the ``WARNING`` level.""" add_message( request, @@ -113,10 +116,11 @@ def warning(request, message, extra_tags="", fail_silently=False): message, extra_tags=extra_tags, fail_silently=fail_silently, + **kwargs, ) -def error(request, message, extra_tags="", fail_silently=False): +def error(request, message, extra_tags="", fail_silently=False, **kwargs): """Add a message with the ``ERROR`` level.""" add_message( request, @@ -124,4 +128,5 @@ def error(request, message, extra_tags="", fail_silently=False): message, extra_tags=extra_tags, fail_silently=fail_silently, + **kwargs, ) diff --git a/django/contrib/messages/storage/base.py b/django/contrib/messages/storage/base.py index 5d89acfe69..3b29679da5 100644 --- a/django/contrib/messages/storage/base.py +++ b/django/contrib/messages/storage/base.py @@ -12,10 +12,11 @@ class Message: or template. """ - def __init__(self, level, message, extra_tags=None): + def __init__(self, level, message, extra_tags=None, **kwargs): self.level = int(level) self.message = message self.extra_tags = extra_tags + self.extra_kwargs = kwargs def _prepare(self): """ @@ -139,7 +140,7 @@ class BaseStorage: messages = self._loaded_messages + self._queued_messages return self._store(messages, response) - def add(self, level, message, extra_tags=""): + def add(self, level, message, extra_tags="", **kwargs): """ Queue a message to be stored. @@ -154,7 +155,7 @@ class BaseStorage: return # Add the message. self.added_new = True - message = Message(level, message, extra_tags=extra_tags) + message = Message(level, message, extra_tags=extra_tags, **kwargs) self._queued_messages.append(message) def _get_level(self):