|
1
|
|
|
from uuid import UUID |
|
2
|
|
|
|
|
3
|
|
|
import diskcache |
|
4
|
|
|
|
|
5
|
|
|
PUE_PAGADA = 'pue_pagada' |
|
6
|
|
|
PPD_IGNORAR = 'ppd_ignorar' |
|
7
|
|
|
EMAIL_NOTIFICADA = 'email_notificada' |
|
8
|
|
|
STATUS_SAT = 'status_sat' |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class LocalDB: |
|
12
|
|
|
def __init__(self): |
|
13
|
|
|
self.local_storage = diskcache.Cache('.data/local') |
|
14
|
|
|
|
|
15
|
|
|
def pue_pagada(self, uuid: UUID): |
|
16
|
|
|
return self.local_storage.get( |
|
17
|
|
|
(PUE_PAGADA, uuid), False |
|
18
|
|
|
) |
|
19
|
|
|
|
|
20
|
|
|
def pue_pagada_set(self, uuid: UUID, value: bool): |
|
21
|
|
|
if value: |
|
22
|
|
|
self.local_storage[(PUE_PAGADA, uuid)] = value |
|
23
|
|
|
else: |
|
24
|
|
|
try: |
|
25
|
|
|
del self.local_storage[(PUE_PAGADA, uuid)] |
|
|
|
|
|
|
26
|
|
|
except KeyError: |
|
27
|
|
|
pass |
|
28
|
|
|
|
|
29
|
|
|
def pue_pagada_flip(self, uuid: UUID): |
|
30
|
|
|
res = not self.pue_pagada(uuid) |
|
31
|
|
|
self.pue_pagada_set(uuid, res) |
|
32
|
|
|
return res |
|
33
|
|
|
|
|
34
|
|
|
def ppd_ignorar(self, uuid: UUID): |
|
35
|
|
|
return self.local_storage.get( |
|
36
|
|
|
(PPD_IGNORAR, uuid), False |
|
37
|
|
|
) |
|
38
|
|
|
|
|
39
|
|
|
def ppd_ignorar_set(self, uuid: UUID, value: bool): |
|
40
|
|
|
if value: |
|
41
|
|
|
self.local_storage[(PPD_IGNORAR, uuid)] = value |
|
42
|
|
|
else: |
|
43
|
|
|
try: |
|
44
|
|
|
del self.local_storage[(PPD_IGNORAR, uuid)] |
|
|
|
|
|
|
45
|
|
|
except KeyError: |
|
46
|
|
|
pass |
|
47
|
|
|
|
|
48
|
|
|
def ppd_ignorar_flip(self, uuid: UUID): |
|
49
|
|
|
res = not self.ppd_ignorar(uuid) |
|
50
|
|
|
self.ppd_ignorar_set(uuid, res) |
|
51
|
|
|
return res |
|
52
|
|
|
|
|
53
|
|
|
def email_notificada(self, uuid: UUID): |
|
54
|
|
|
return self.local_storage.get( |
|
55
|
|
|
(EMAIL_NOTIFICADA, uuid), False |
|
56
|
|
|
) |
|
57
|
|
|
|
|
58
|
|
|
def email_notificada_set(self, uuid: UUID, value: bool): |
|
59
|
|
|
if value: |
|
60
|
|
|
self.local_storage[(EMAIL_NOTIFICADA, uuid)] = value |
|
61
|
|
|
else: |
|
62
|
|
|
try: |
|
63
|
|
|
del self.local_storage[(EMAIL_NOTIFICADA, uuid)] |
|
|
|
|
|
|
64
|
|
|
except KeyError: |
|
65
|
|
|
pass |
|
66
|
|
|
|
|
67
|
|
|
def email_notificada_flip(self, uuid: UUID): |
|
68
|
|
|
res = not self.email_notificada(uuid) |
|
69
|
|
|
self.email_notificada_set(uuid, res) |
|
70
|
|
|
return res |
|
71
|
|
|
|
|
72
|
|
|
def status_sat(self, uuid: UUID): |
|
73
|
|
|
return self.local_storage.get( |
|
74
|
|
|
(STATUS_SAT, uuid), {} |
|
75
|
|
|
) |
|
76
|
|
|
|
|
77
|
|
|
def status_sat_set(self, uuid: UUID, value: dict): |
|
78
|
|
|
if value: |
|
79
|
|
|
self.local_storage[(STATUS_SAT, uuid)] = value |
|
80
|
|
|
else: |
|
81
|
|
|
try: |
|
82
|
|
|
del self.local_storage[(STATUS_SAT, uuid)] |
|
|
|
|
|
|
83
|
|
|
except KeyError: |
|
84
|
|
|
pass |
|
85
|
|
|
|