Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/django/core/checks/messages.py: 78%
38 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1# Levels
2DEBUG = 10
3INFO = 20
4WARNING = 30
5ERROR = 40
6CRITICAL = 50
9class CheckMessage:
10 def __init__(self, level, msg, hint=None, obj=None, id=None):
11 if not isinstance(level, int): 11 ↛ 12line 11 didn't jump to line 12, because the condition on line 11 was never true
12 raise TypeError("The first argument should be level.")
13 self.level = level
14 self.msg = msg
15 self.hint = hint
16 self.obj = obj
17 self.id = id
19 def __eq__(self, other):
20 return isinstance(other, self.__class__) and all(
21 getattr(self, attr) == getattr(other, attr)
22 for attr in ["level", "msg", "hint", "obj", "id"]
23 )
25 def __str__(self):
26 from django.db import models
28 if self.obj is None:
29 obj = "?"
30 elif isinstance(self.obj, models.base.ModelBase):
31 # We need to hardcode ModelBase and Field cases because its __str__
32 # method doesn't return "applabel.modellabel" and cannot be changed.
33 obj = self.obj._meta.label
34 else:
35 obj = str(self.obj)
36 id = "(%s) " % self.id if self.id else ""
37 hint = "\n\tHINT: %s" % self.hint if self.hint else ""
38 return "%s: %s%s%s" % (obj, id, self.msg, hint)
40 def __repr__(self):
41 return "<%s: level=%r, msg=%r, hint=%r, obj=%r, id=%r>" % (
42 self.__class__.__name__,
43 self.level,
44 self.msg,
45 self.hint,
46 self.obj,
47 self.id,
48 )
50 def is_serious(self, level=ERROR):
51 return self.level >= level
53 def is_silenced(self):
54 from django.conf import settings
56 return self.id in settings.SILENCED_SYSTEM_CHECKS
59class Debug(CheckMessage):
60 def __init__(self, *args, **kwargs):
61 super().__init__(DEBUG, *args, **kwargs)
64class Info(CheckMessage):
65 def __init__(self, *args, **kwargs):
66 super().__init__(INFO, *args, **kwargs)
69class Warning(CheckMessage):
70 def __init__(self, *args, **kwargs):
71 super().__init__(WARNING, *args, **kwargs)
74class Error(CheckMessage):
75 def __init__(self, *args, **kwargs):
76 super().__init__(ERROR, *args, **kwargs)
79class Critical(CheckMessage):
80 def __init__(self, *args, **kwargs):
81 super().__init__(CRITICAL, *args, **kwargs)