Mercurial > libervia-backend
changeset 3307:9f0e28137cd0
tools (common/data_objects): implemented `json` dumping for BlogItems/BlogItem
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Jun 2020 15:47:16 +0200 |
parents | 3af0909629a2 |
children | 384283adcce1 |
files | sat/tools/common/data_objects.py |
diffstat | 1 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/tools/common/data_objects.py Fri Jun 19 15:45:57 2020 +0200 +++ b/sat/tools/common/data_objects.py Fri Jun 19 15:47:16 2020 +0200 @@ -87,6 +87,19 @@ self._comments = None self._comments_items_list = None + def json(self): + ret = {} + for attr in ( + "id", "atom_id", "uri", "published", "updated", "language", "author", + "author_jid", "author_jid_verified", "author_email", "tags", "groups", + "title", "title_xhtml", "content", "content_xhtml", "comments", + "comments_service", "comments_node", "comments_items_list" + ): + value = getattr(self, attr) + if value is not None: + ret[attr] = value + return ret + @property def id(self): return self.mb_data.get("id") @@ -198,6 +211,18 @@ self.items = [BlogItem(i, self, deserialise=deserialise) for i in mb_data[0]] self.metadata = parsePubSubMetadata(mb_data[1], self.items) + def json(self): + ret = { + "items": [i.json() for i in self.items], + } + for attr in ("service", "node", "uri", "with_rsm"): + ret[attr] = getattr(self, attr) + if self.with_rsm: + for attr in ("rsm_first", "rsm_last", "rsm_index", "rsm_count", "complete"): + ret[attr] = getattr(self, attr) + + return ret + @property def service(self): return self.metadata["service"]