def enable(self): super(override_settings_tags, self).enable() # LEVEL_TAGS is a constant defined in the # djangocg.contrib.messages.storage.base module, so after changing # settings.MESSAGE_TAGS, we need to update that constant too. self.old_level_tags = base.LEVEL_TAGS base.LEVEL_TAGS = utils.get_level_tags()
from __future__ import unicode_literals from djangocg.conf import settings from djangocg.utils.encoding import force_text, python_2_unicode_compatible from djangocg.contrib.messages import constants, utils LEVEL_TAGS = utils.get_level_tags() @python_2_unicode_compatible class Message(object): """ Represents an actual message that can be stored in any of the supported storage classes (typically session- or cookie-based) and rendered in a view or template. """ def __init__(self, level, message, extra_tags=None): self.level = int(level) self.message = message self.extra_tags = extra_tags def _prepare(self): """ Prepares the message for serialization by forcing the ``message`` and ``extra_tags`` to unicode in case they are lazy translations. Known "safe" types (None, int, etc.) are not converted (see Django's ``force_text`` implementation for details). """