Coverage for portality/models/event.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-22 15:59 +0100

1from portality.lib import dates 

2import json 

3 

4 

5class Event(object): 

6 def __init__(self, id=None, who=None, context=None, raw=None): 

7 if raw is not None: 

8 self.data = raw 

9 else: 

10 self.data = { 

11 "when" : dates.now() 

12 } 

13 if id is not None: 

14 self.id = id 

15 if who is not None: 

16 self.who = who 

17 if context: 

18 self.set_context(**context) 

19 

20 @property 

21 def id(self): 

22 return self.data.get("id") 

23 

24 @id.setter 

25 def id(self, val): 

26 self.data["id"] = val 

27 

28 @property 

29 def who(self): 

30 return self.data.get("who") 

31 

32 @who.setter 

33 def who(self, val): 

34 self.data["who"] = val 

35 

36 @property 

37 def context(self): 

38 return self.data.get("context", {}) 

39 

40 def set_context(self, **kwargs): 

41 self.data["context"] = kwargs 

42 

43 def serialise(self): 

44 return json.dumps(self.data) 

45 

46 @property 

47 def when(self): 

48 return self.data.get("when")