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

Can't define custom message levels for persistent messages? #5

Open
anentropic opened this issue Jul 3, 2014 · 2 comments
Open

Can't define custom message levels for persistent messages? #5

anentropic opened this issue Jul 3, 2014 · 2 comments

Comments

@anentropic
Copy link

I haven't tried yet, but reading through the code there is this in Message model:

LEVEL_CHOICES = (
    (messages_extends.DEBUG_PERSISTENT, 'PERSISTENT DEBUG'),
    (messages_extends.INFO_PERSISTENT, 'PERSISTENT INFO'),
    (messages_extends.SUCCESS_PERSISTENT, 'PERSISTENT SUCCESS'),
    (messages_extends.WARNING_PERSISTENT, 'PERSISTENT WARNING'),
    (messages_extends.ERROR_PERSISTENT, 'PERSISTENT ERROR'),
    )
level = models.IntegerField(choices=LEVEL_CHOICES)

this would appear to make it impossible to define your own levels for persistent messages

this should either not be validated, or perhaps LEVEL_CHOICES could be provided as a default but overridable from settings.py ?

@AliLozano
Copy link
Owner

That's only validation for admins forms, you don't need it for use any level from code:

 messages.add_message(request, ANY_NUYMBER, 'Hello world.')

But by other hand, you have reason, you can't customize PERSISTENT_MESSAGES_LEVELS, because storage searchs levels from messages.extends.constants.

I'll check it for be more customizable.

Thanks.

@JanMalte
Copy link
Contributor

@AliLozano actually the message only gets processed and saved by the PersistentStorage, if the message level is in PERSISTENT_MESSAGE_LEVELS.
Therefor adding a custom persistant message level is currently not possible without overwriting the message storage.

def process_message(self, message, *args, **kwargs):
"""
If its level is into persist levels, convert the message to models and save it
"""
if not message.level in PERSISTENT_MESSAGE_LEVELS:
return message

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

No branches or pull requests

3 participants