Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customization of message-to-alert mapping #241

Open
greyhare opened this issue Nov 24, 2020 · 2 comments
Open

Customization of message-to-alert mapping #241

greyhare opened this issue Nov 24, 2020 · 2 comments

Comments

@greyhare
Copy link

In bootstrap4/templatetags/bootstrap4.py, there's a function bootstrap_message_classes which figures out what classes to assign to a Bootstrap Alert generated from a Django message. Right now, it makes the obvious mappings, except for two:

  • message_constants.DEBUG is mapped to alert-warning, and
  • messages without a proper level set get alert-danger.

Personally, I'd like DEBUG mapped to alert-secondary (gray background) and the default to be alert-primary (darker blue background) because I don't want things that aren't warnings or errors to look like them. Others might want to use alert-light or alert-dark. But there's no obvious way to change this. Monkeypatching the function might not work because @register.filter would still register the old one. Maybe I could alter MESSAGE_LEVEL_CLASSES, but is that the right way?

@greyhare
Copy link
Author

I've gotten this to work in my settings.py, but I have no idea how fragile it is:

from bootstrap4.templatetags import bootstrap4
from django.contrib.messages import constants
bootstrap4.MESSAGE_LEVEL_CLASSES[constants.DEBUG] = 'alert alert-secondary'
bootstrap4.MESSAGE_LEVEL_CLASSES[99] = 'alert alert-primary'

The 99 is the value I use to test the default case. Needless to say, this doesn't really change the default styling, and one would need to find all the messages that didn't use constants and set values for them in the dict.

This really needs to be something we can set in settings.BOOTSTRAP4.

@dyve
Copy link
Member

dyve commented May 1, 2021

Makes sense to be able to set this. I'll also check the django-bootstrap5 version of this issue and see what I can come up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants