summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSjoerd Langkemper <sjoerd@byte.nl>2013-11-07 16:50:51 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2013-11-11 17:58:02 +0100
commitd87127655f540747e7dc83badc015ea520b880f5 (patch)
treee1f8ff285a3a0f49c3b1f11d745a311a8e28db87 /docs
parentf67cce0434907ef00db25577d46fdd04c0ad765d (diff)
Fixed #21421 -- Added level_tag attribute on messages.
Exposing the level name (e.g. "info") makes it possible to prepend something to the class name. For example, Twitter Bootstrap has an alert-info class. This class can now be added to the message using `class="alert-{{ message.level_tag }}". Because the level_tag was on the end of the `tags` property, it could not be used in this fashion when extra_tags were given.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/messages.txt26
-rw-r--r--docs/releases/1.7.txt4
2 files changed, 30 insertions, 0 deletions
diff --git a/docs/ref/contrib/messages.txt b/docs/ref/contrib/messages.txt
index caf51d26cc..690b73d195 100644
--- a/docs/ref/contrib/messages.txt
+++ b/docs/ref/contrib/messages.txt
@@ -212,6 +212,32 @@ is a mapping of the message level names to their numeric value::
</ul>
{% endif %}
+The ``Message`` class
+---------------------
+
+.. class:: storage.base.Message
+
+ When you loop over the list of messages in a template, what you get are
+ instances of the ``Message`` class. It's quite a simple object, with only a
+ few attributes:
+
+ * ``message``: The actual text of the message.
+
+ * ``level``: An integer describing the type of the message (see the
+ `message levels`_ section above).
+
+ * ``tags``: A string combining all the message's tags (``extra_tags`` and
+ ``level_tag``) separated by spaces.
+
+ * ``extra_tags``: A string containing custom tags for this message,
+ separated by spaces. It's empty by default.
+
+ .. versionadded:: 1.7
+
+ * ``level_tag``: The string representation of the level. By default, it's
+ the lowercase version of the name of the associated constant, but this
+ can be changed if you need by using the :setting:`MESSAGE_TAGS` setting.
+
Creating custom message levels
------------------------------
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index d703f44e4b..7b527ce7fb 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -221,6 +221,10 @@ Minor features
* The :ref:`messages context processor <message-displaying>` now adds a
dictionary of default levels under the name ``DEFAULT_MESSAGE_LEVELS``.
+* :class:`~django.contrib.messages.storage.base.Message` objects now have a
+ ``level_tag`` attribute that contains the string representation of the
+ message level.
+
:mod:`django.contrib.redirects`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^