# HG changeset patch # User Goffi # Date 1592574436 -7200 # Node ID 9f0e28137cd06a00e6d42517a8fec61ed864100a # Parent 3af0909629a200d911c8d893ca3a1940a58e3165 tools (common/data_objects): implemented `json` dumping for BlogItems/BlogItem diff -r 3af0909629a2 -r 9f0e28137cd0 sat/tools/common/data_objects.py --- 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"]