tools (common/data_objects): implemented json dumping for BlogItems/BlogItem
This commit is contained in:
parent
4b0d91cb2e
commit
282d2a93d9
1 changed files with 25 additions and 0 deletions
|
|
@ -87,6 +87,19 @@ class BlogItem(object):
|
|||
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 @@ class BlogItems(object):
|
|||
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"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue