comparison sat/tools/common/data_objects.py @ 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 9896589487ae
children e4121a1f2399
comparison
equal deleted inserted replaced
3306:3af0909629a2 3307:9f0e28137cd0
85 self.mb_data = mb_data 85 self.mb_data = mb_data
86 self.parent = parent 86 self.parent = parent
87 self._comments = None 87 self._comments = None
88 self._comments_items_list = None 88 self._comments_items_list = None
89 89
90 def json(self):
91 ret = {}
92 for attr in (
93 "id", "atom_id", "uri", "published", "updated", "language", "author",
94 "author_jid", "author_jid_verified", "author_email", "tags", "groups",
95 "title", "title_xhtml", "content", "content_xhtml", "comments",
96 "comments_service", "comments_node", "comments_items_list"
97 ):
98 value = getattr(self, attr)
99 if value is not None:
100 ret[attr] = value
101 return ret
102
90 @property 103 @property
91 def id(self): 104 def id(self):
92 return self.mb_data.get("id") 105 return self.mb_data.get("id")
93 106
94 @property 107 @property
195 be deserialised 208 be deserialised
196 """ 209 """
197 # FIXME: deserialise should not be done here, but before BlogItem is called 210 # FIXME: deserialise should not be done here, but before BlogItem is called
198 self.items = [BlogItem(i, self, deserialise=deserialise) for i in mb_data[0]] 211 self.items = [BlogItem(i, self, deserialise=deserialise) for i in mb_data[0]]
199 self.metadata = parsePubSubMetadata(mb_data[1], self.items) 212 self.metadata = parsePubSubMetadata(mb_data[1], self.items)
213
214 def json(self):
215 ret = {
216 "items": [i.json() for i in self.items],
217 }
218 for attr in ("service", "node", "uri", "with_rsm"):
219 ret[attr] = getattr(self, attr)
220 if self.with_rsm:
221 for attr in ("rsm_first", "rsm_last", "rsm_index", "rsm_count", "complete"):
222 ret[attr] = getattr(self, attr)
223
224 return ret
200 225
201 @property 226 @property
202 def service(self): 227 def service(self):
203 return self.metadata["service"] 228 return self.metadata["service"]
204 229