Add a message level dict to `contrib.messages.context_processors.messages`
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).
Has patch: |
set
|
Needs documentation: |
set
|
Needs tests: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Version: |
→ master
|
Needs documentation: |
unset
|
Needs tests: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
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.