Opened 3 years ago

Closed 3 years ago

#21421 closed New feature (fixed)

Expose level tag (debug, info, warning) on messages

Reported by: sjoerd-django@… Owned by: nobody
Component: contrib.messages Version: master
Severity: Normal Keywords:
Cc: Baptiste Mispelon Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Messages in the messages framework have a level, like debug, info or warning. It would be nice if this level was accessible in the view, so that it can be used in a class name. For example, Twitter Bootstrap has
an alert-info class. This class could be added to the message using class="alert-{{ message.level_tag }}".

The existing extra_tags functionality does not provide for this, because the level_tag is on the end. When using class="alert-{{ message.extra_tags }}" it will only work when no extra tags are given.

I have made a pull request for this here:

Change History (3)

comment:1 Changed 3 years ago by Baptiste Mispelon

Cc: Baptiste Mispelon added
Has patch: set
Needs documentation: set
Needs tests: unset
Patch needs improvement: set
Triage Stage: UnreviewedAccepted


This looks like an interesting addition.

The pull request looks good but it's lacking documentation. The new feature should be described in the messages framework documentation and a release note should be added for the 1.7 release.

I'm adding the "patch needs improvement" flag for this reason. You can remove it when you update the pull request.


comment:2 Changed 3 years ago by sjoerd-django@…

Patch needs improvement: unset

I have modified the code according to your remarks and I added some documentation. Any feedback on the documentation is welcome.

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

Resolution: fixed
Status: newclosed

In d87127655f540747e7dc83badc015ea520b880f5:

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.

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