diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-04-27 16:12:58 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-04-27 16:12:58 +0200 |
commit | f0d5701c7cbc07afb46fafaf06bc51354451947b (patch) | |
tree | 75389b49e037a564d83b2ac669ab14c3d86bbe53 | |
parent | 04d349cae45b2d37f009fe87113615eb7093d6e6 (diff) |
Explicitely set the id on every object
-rw-r--r-- | pyapd/objects.py | 12 |
1 files 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 |