-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccounts.py
87 lines (75 loc) · 1.93 KB
/
accounts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from datetime import datetime
import json
class Account:
"""
Abstract class that represents account entities
created from JSON object received from API
"""
def __init__(self, account):
self.account = account
self.add_base_fields()
def add_base_fields(self):
"""
Adds some base fields to an account object
"""
_id = self.get_id()
self.account.update({
"_id": _id,
})
def get_id(self):
"""
Returns unique id of an entity
"""
return self.account['name']
def to_dict(self):
"""
Returns dictionary that represents entity that should be stored
in a database
"""
return self.account
def use_connector(self, connector):
"""
Abstract method to do something with the connector before save
"""
pass
def get_collection(self):
"""
Returns collection where accounts should be stored
"""
return "account_object"
def get_query(self):
"""
Returns unique query to find account
"""
return {"_id": self.get_id()}
class NeedUpdateAccount(Account):
"""
Class to pre-save partial JSON object
in the operation object received from API
"""
def __init__(self, account):
super().__init__(account)
account['need_update'] = True
class UpdatedAccount(Account):
"""
Class to prepare JSON object received from API
to transfer to a database.
"""
BLACKLIST = ['posting', 'owner', 'active']
def __init__(self, account):
super().__init__(account)
self.set_need_update()
self.remove_blacklisted_fields()
def set_need_update(self):
"""
Resets need_update flag of an account
"""
account['need_update'] = False
def remove_blacklisted_fields(self):
"""
Removes blacklisted fields from JSON object.
This method is temporary, will be removed in next releases
"""
for key in self.BLACKLIST:
if key in account.keys():
del account[key]