Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20610 closed New feature (fixed)

Add a message level dict to `contrib.messages.context_processors.messages`

Reported by: Baptiste Mispelon Owned by: nobody
Component: contrib.messages Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It'd be nice if the provided context processor also added a dictionary of message levels to the context.

This would allow something like this:

{% for message in messages %}
    {% if message.level == MESSAGE_LEVELS.SUCCESS %}...{% endif %}
    ...
{% endfor %}

Currently, one has to pass the message levels manually into the context, or do something like this, which is brittle:

{% if 'success' i nmessage.tags %}...{% endif %}

There should not be any backwards-compatibility issue and the change is rather minimal.
I've attached a proof-of-concept patch. If there's interest, I'd be willing to polish it up (mostly adding tests and documentation).

Attachments (1)

message-level-dict.patch (804 bytes ) - added by Baptiste Mispelon 11 years ago.

Download all attachments as: .zip

Change History (7)

by Baptiste Mispelon, 11 years ago

Attachment: message-level-dict.patch added

comment:1 by Aymeric Augustin, 11 years ago

Technically, it's backwards incompatible for people who have "MESSAGE_LEVELS" in their context. That's minor, but it should be mentioned in the release notes.

comment:2 by Tim Graham, 11 years ago

Has patch: set
Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted
Version: master

comment:3 by Baptiste Mispelon, 11 years ago

Needs documentation: unset
Needs tests: unset

Here's a pull request with tests and documentation: https://github.com/django/django/pull/1822

comment:4 by Tim Graham, 11 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Baptiste Mispelon <bmispelon@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 9fde42a69a56cb6c8cdfd67b07c67a1b97638f12:

Fixed #20610: Added a message level dict to contrib.message context processor.

comment:6 by Claude Paroz <claude@…>, 11 years ago

In 79e4a189f3b17b5a7426f889c4412126eb169256:

[1.7.x] Updated the messages context processor docs

Refs #20610.
Backport of 7951f125e frmo master.

Note: See TracTickets for help on using tickets.
Back to Top