MCPcopy
hub / github.com/django/django / Message

Class Message

django/contrib/messages/storage/base.py:8–46  ·  view source on GitHub ↗

Represent 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.

Source from the content-addressed store, hash-verified

6
7
8class Message:
9 """
10 Represent an actual message that can be stored in any of the supported
11 storage classes (typically session- or cookie-based) and rendered in a view
12 or template.
13 """
14
15 def __init__(self, level, message, extra_tags=None):
16 self.level = int(level)
17 self.message = message
18 self.extra_tags = extra_tags
19
20 def _prepare(self):
21 """
22 Prepare the message for serialization by forcing the ``message``
23 and ``extra_tags`` to str in case they are lazy translations.
24 """
25 self.message = str(self.message)
26 self.extra_tags = str(self.extra_tags) if self.extra_tags is not None else None
27
28 def __eq__(self, other):
29 if not isinstance(other, Message):
30 return NotImplemented
31 return self.level == other.level and self.message == other.message
32
33 def __str__(self):
34 return str(self.message)
35
36 def __repr__(self):
37 extra_tags = f", extra_tags={self.extra_tags!r}" if self.extra_tags else ""
38 return f"Message(level={self.level}, message={self.message!r}{extra_tags})"
39
40 @property
41 def tags(self):
42 return " ".join(tag for tag in [self.extra_tags, self.level_tag] if tag)
43
44 @property
45 def level_tag(self):
46 return LEVEL_TAGS.get(self.level, "")
47
48
49class BaseStorage:

Callers 15

process_messagesMethod · 0.90
test_eqMethod · 0.90
test_reprMethod · 0.90
test_assertionMethod · 0.90
test_with_tagsMethod · 0.90
test_custom_levelnameMethod · 0.90
test_orderedMethod · 0.90
addMethod · 0.90
test_multiple_postsMethod · 0.90
get_existing_storageMethod · 0.90
test_safedataMethod · 0.90

Calls

no outgoing calls

Tested by 13

test_eqMethod · 0.72
test_reprMethod · 0.72
test_assertionMethod · 0.72
test_with_tagsMethod · 0.72
test_custom_levelnameMethod · 0.72
test_orderedMethod · 0.72
test_multiple_postsMethod · 0.72
test_safedataMethod · 0.72
encode_decodeMethod · 0.72