Passed
Push — develop ( c6fa42...950d5f )
by Dean
02:50
created

Message.viewed()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.6875

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 1
cts 4
cp 0.25
rs 9.4285
c 0
b 0
f 0
cc 2
crap 3.6875
1 1
from plugin.core.environment import translate as _
2 1
from plugin.models.core import db
3
4 1
from exception_wrappers.libraries.playhouse.apsw_ext import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like exception_wrappers.libraries.playhouse.apsw_ext should generally be avoided.
Loading history...
5
6
7 1
class MessageCode(object):
8
    # Database (0x09)
9
    # - Schema (0x0901)
10 1
    DatabaseSchemaCorruptionReset = 0x90101
11
12
    # Release / Version (0x10)
13
    # - Upgrade (0x1001)
14 1
    UpgradePerformed = 0x100101
15
    # - Downgrade (0x1002)
16 1
    DowngradeUnclean = 0x100201
17
18
    # Network (0x11)
19
    # - Trakt (0x1101)
20 1
    TraktTimeout = 0x110101
21
22
    # TODO check for conflicting codes
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
23
24
25 1
class MessageType(object):
26 1
    __titles__  = None
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
__titles__ = None
^
Loading history...
27
28 1
    Generic     = 0x00
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Generic = 0x00
^
Loading history...
29 1
    Exception   = 0x01
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Exception = 0x01
^
Loading history...
30
31
    # Basic messages
32 1
    Info        = 0x02
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Info = 0x02
^
Loading history...
33 1
    Warning     = 0x04
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Warning = 0x04
^
Loading history...
34 1
    Error       = 0x08
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Error = 0x08
^
Loading history...
35 1
    Critical    = 0x16
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Critical = 0x16
^
Loading history...
36
37
    # Services
38 1
    Trakt       = 0x32
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Trakt = 0x32
^
Loading history...
39 1
    Plex        = 0x64
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Plex = 0x64
^
Loading history...
40 1
    Sentry      = 0x128
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Sentry = 0x128
^
Loading history...
41
42 1
    @classmethod
43
    def title(cls, value):
44
        if cls.__titles__ is None:
45
            cls.__titles__ = {
46
                MessageType.Generic:    None,
47
                MessageType.Exception:  _("Exception"),
48
49
                MessageType.Info:       _("Info"),
50
                MessageType.Warning:    _("Warning"),
51
                MessageType.Error:      _("Error"),
52
                MessageType.Critical:   _("Critical"),
53
54
                MessageType.Trakt:      _("Trakt.tv"),
55
                MessageType.Plex:       _("Plex.tv"),
56
                MessageType.Sentry:     _("Sentry")
57
            }
58
59
        return cls.__titles__.get(value)
60
61
62 1
class Message(Model):
63 1
    Code = MessageCode
64 1
    Type = MessageType
65
66 1
    class Meta:
67 1
        database = db
68 1
        db_table = 'message'
69
70 1
        indexes = (
71
            (('type', 'exception_hash'), True),
72
        )
73
74 1
    code = IntegerField(null=True)
75 1
    type = IntegerField()
76
77 1
    last_logged_at = DateTimeField()
78 1
    last_viewed_at = DateTimeField(null=True)
79
80
    # Tracking data
81 1
    exception_hash = CharField(null=True, max_length=32)
82 1
    revision = IntegerField(null=True)
83
84 1
    version_base = CharField(max_length=12)
85 1
    version_branch = CharField(max_length=42)
86
87
    # User-friendly explanation
88 1
    summary = CharField(null=True, max_length=160)  # Short single-line summary
89 1
    description = TextField(null=True)  # Extra related details
90
91 1
    @property
92
    def viewed(self):
93
        if not self.last_viewed_at:
94
            return False
95
96
        return self.last_viewed_at > self.last_logged_at
97