Passed
Push — develop ( 9e1b8b...5d0b21 )
by Dean
03:00
created

Session.account_id()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 1
cts 2
cp 0.5
rs 10
c 0
b 0
f 0
cc 1
crap 1.125
1 1
from plugin.models.core import db
2 1
from plugin.models.account import Account
3 1
from plugin.models.client import Client
4 1
from plugin.models.user import User
5
6 1
from playhouse.apsw_ext import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like playhouse.apsw_ext should generally be avoided.
Loading history...
7
8
9 1
class Session(Model):
10 1
    class Meta:
11 1
        database = db
12
13 1
    account = ForeignKeyField(Account, 'sessions', null=True)
14 1
    client = ForeignKeyField(Client, 'sessions', to_field='key', null=True)
15 1
    user = ForeignKeyField(User, 'sessions', to_field='key', null=True)
16
17 1
    rating_key = IntegerField(null=True)
18 1
    session_key = TextField(null=True, unique=True)
19
20 1
    state = CharField(null=True)
21
22 1
    part = IntegerField(default=1)
23 1
    part_count = IntegerField(default=1)
24 1
    part_duration = IntegerField(null=True)
25
26 1
    duration = IntegerField(null=True)
27 1
    view_offset = IntegerField(null=True)
28 1
    progress = FloatField(null=True)
29
30 1
    updated_at = DateTimeField(null=True)
31
32 1
    @property
33
    def account_id(self):
34
        return self._data.get('account')
35
36 1
    @property
37
    def payload(self):
38
        return {
39
            'part': self.part,
40
            'rating_key': self.rating_key,
41
            'view_offset': self.view_offset
42
        }
43
44 1
    def __repr__(self):
45
        return '<Session session_key: %r, state: %r>' % (
46
            self.session_key,
47
            self.state
48
        )
49