Opened 6 years ago

Closed 6 years ago

Last modified 5 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: master
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


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 6 years ago.

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by Baptiste Mispelon

Attachment: message-level-dict.patch added

comment:1 Changed 6 years ago by Aymeric Augustin

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 Changed 6 years ago by Tim Graham

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

comment:3 Changed 6 years ago by Baptiste Mispelon

Needs documentation: unset
Needs tests: unset

Here's a pull request with tests and documentation:

comment:4 Changed 6 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:5 Changed 6 years ago by Baptiste Mispelon <bmispelon@…>

Resolution: fixed
Status: newclosed

In 9fde42a69a56cb6c8cdfd67b07c67a1b97638f12:

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

comment:6 Changed 5 years ago by Claude Paroz <claude@…>

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