Mercurial > libervia-backend
diff sat_frontends/jp/cmd_blog.py @ 3308:384283adcce1
plugins XEP-0059, XEP-0060, XEP-0277, XEP-0313: better serialisation:
`data_format.serialise` is now used for `mbGet`, and RSM/MAM values are not transtyped to
strings anymore. A serialised dict is now used, items are put in the `items` key.
Comments handling has been refactored to use a list for the potentially multiple comments
nodes.
`rsm` data are now in a `rsm` key of the dict, and `mam` data are merged with other
metadata.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 16 Jul 2020 09:07:20 +0200 |
parents | 46f0b388eeea |
children | 9dbe2517d131 |
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_blog.py Fri Jun 19 15:47:16 2020 +0200 +++ b/sat_frontends/jp/cmd_blog.py Thu Jul 16 09:07:20 2020 +0200 @@ -33,7 +33,6 @@ from sat_frontends.jp.constants import Const as C from sat_frontends.jp import common from sat.tools.common.ansi import ANSI as A -from sat.tools.common import data_objects from sat.tools.common import uri from sat.tools import config from configparser import NoSectionError, NoOptionError @@ -262,7 +261,9 @@ # TODO: add MAM filters def template_data_mapping(self, data): - return {"items": data_objects.BlogItems(data, deserialise=False)} + items, blog_items = data + blog_items['items'] = items + return {"blog_items": blog_items} def format_comments(self, item, keys): comments_data = data_format.dict2iterdict( @@ -424,22 +425,22 @@ async def start(self): try: - mb_result = await self.host.bridge.mbGet( - self.args.service, - self.args.node, - self.args.max, - self.args.items, - self.getPubsubExtra(), - self.profile + mb_data = data_format.deserialise( + await self.host.bridge.mbGet( + self.args.service, + self.args.node, + self.args.max, + self.args.items, + self.getPubsubExtra(), + self.profile + ) ) except Exception as e: self.disp(f"can't get blog items: {e}", error=True) self.host.quit(C.EXIT_BRIDGE_ERRBACK) else: - items, metadata = mb_result - items = [data_format.deserialise(i) for i in items] - mb_result = items, metadata - await self.output(mb_result) + items = mb_data.pop('items') + await self.output((items, mb_data)) self.host.quit(C.EXIT_OK) @@ -592,14 +593,17 @@ async def getItemData(self, service, node, item): items = [item] if item else [] - mb_data = await self.host.bridge.mbGet( - service, node, 1, items, {}, self.profile) - mb_data = data_format.deserialise(mb_data[0][0]) + mb_data = data_format.deserialise( + await self.host.bridge.mbGet( + service, node, 1, items, {}, self.profile + ) + ) + item = mb_data['items'][0] try: - content = mb_data["content_xhtml"] + content = item["content_xhtml"] except KeyError: - content = mb_data["content"] + content = item["content"] if content: content = await self.host.bridge.syntaxConvert( content, "text", SYNTAX_XHTML, False, self.profile @@ -623,7 +627,7 @@ root = etree.fromstring(content, parser) content = etree.tostring(root, encoding=str, pretty_print=True) - return content, mb_data, mb_data["id"] + return content, item, item["id"] async def start(self): # if there are user defined extension, we use them