From f0d5701c7cbc07afb46fafaf06bc51354451947b Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 27 Apr 2019 16:12:58 +0200 Subject: Explicitely set the id on every object --- pyapd/objects.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pyapd/objects.py b/pyapd/objects.py index 6750b09..2fa2e03 100644 --- a/pyapd/objects.py +++ b/pyapd/objects.py @@ -3,7 +3,6 @@ import json class Object(): PROPERTIES = [ - 'id', 'type', 'attachment', 'attributedTo', @@ -41,13 +40,19 @@ class Object(): for p in self.PROPERTIES: if p in kw: setattr(self, "ap_"+p, kw[p]) + if 'id' in kw: + self.ap_id = kw['id'] + else: + self.ap_id = self._generate_id() @classmethod def from_jsons(cls, data: str): return cls(**json.loads(data)) def to_jsonable(self): - data = {} + data = { + 'id': self.ap_id, + } for p in self.PROPERTIES: v = getattr(self, "ap_"+p, None) if v is not None: @@ -56,3 +61,6 @@ class Object(): def to_jsons(self): return json.dumps(self.to_jsonable()) + + def _generate_id(self): + raise NotImplementedError -- cgit v1.2.3