forked from pritunl/pritunl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_mongo.py
48 lines (35 loc) · 1.04 KB
/
group_mongo.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
from pritunl.settings.group_base import SettingsGroupBase
from pritunl.constants import *
class SettingsGroupMongo(SettingsGroupBase):
type = GROUP_MONGO
def __init__(self):
self.changed = set()
self.unseted = set()
def __setattr__(self, name, value):
if name != 'fields' and name in self.fields:
self.changed.add(name)
object.__setattr__(self, name, value)
def unset(self, name):
self.unseted.add(name)
try:
delattr(self, name)
except AttributeError:
pass
def get_commit_doc(self, init):
doc = {
'_id': self.group,
}
for field in self.changed:
doc[field] = getattr(self, field)
self.changed = set()
if init or len(doc) > 1:
return doc
def get_commit_unset_doc(self):
doc = {
'_id': self.group,
}
for field in self.unseted:
doc[field] = ""
self.unseted = set()
if len(doc) > 1:
return doc