#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)
Change History (7)
by , 11 years ago
Attachment: | message-level-dict.patch added |
---|
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Version: | → master |
comment:3 by , 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 , 11 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 11 years ago
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.