Mercurial > libervia-backend
diff sat_frontends/jp/cmd_blog.py @ 2807:0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
So far, and for historical reasons, blog items data where serialised using a unicode: unicode dict, which was causing trouble for many types of values (timestamps, booleans, lists).
This patch changes it by serialising the whole items before going to bridge, and deserialising it when going back. This way, complex data can be used easily in items.
This impact psEvent and serItemsData* methods which are renamed transItemsData* because there are not always serialising anymore (a new argument "serialise" allows to specify it).
When editing a blog post in jp, metadata are now more easy to manipulate, specially lists like tags.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 23 Feb 2019 18:59:00 +0100 |
parents | 003b8b4b56a7 |
children | 51c53fc4fc4a |
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_blog.py Wed Feb 20 19:42:35 2019 +0100 +++ b/sat_frontends/jp/cmd_blog.py Sat Feb 23 18:59:00 2019 +0100 @@ -142,9 +142,10 @@ if metadata already exist, it will be overwritten """ - mb_data["allow_comments"] = C.boolConst(self.args.comments) + if self.args.comments is not None: + mb_data["allow_comments"] = self.args.comments if self.args.tag: - data_format.iter2dict("tag", self.args.tag, mb_data, check_conflict=False) + mb_data[u'tags'] = self.args.tag if self.args.title is not None: mb_data["title"] = self.args.title @@ -179,7 +180,7 @@ self.host.bridge.mbSend( self.args.service, self.args.node, - mb_data, + data_format.serialise(mb_data), self.profile, callback=self.exitCb, errback=partial( @@ -239,7 +240,7 @@ return u"\n".join(lines) def format_tags(self, item, keys): - tags = data_format.dict2iter("tag", item, pop=True) + tags = item.pop(u'tags', []) return u", ".join(tags) def format_updated(self, item, keys): @@ -318,6 +319,8 @@ sep=u"\n" if "content" in k else u"", ) value = k_cb[k](item, keys) if k in k_cb else item[k] + if isinstance(value, bool): + value = unicode(value).lower() self.disp(header + value) # we want a separation line after each item but the last one if idx < len(items) - 1: @@ -353,7 +356,7 @@ else: author = published = updated = None if verbosity > 1: - tags = list(data_format.dict2iter("tag", item, pop=True)) + tags = item.pop('tags', []) else: tags = None content = item.get(u"content") @@ -380,6 +383,9 @@ print(u"\n" + sep + "\n") def mbGetCb(self, mb_result): + items, metadata = mb_result + items = [data_format.deserialise(i) for i in items] + mb_result = items, metadata self.output(mb_result) self.host.quit(C.EXIT_OK) @@ -527,6 +533,8 @@ if self.pubsub_item is not None: mb_data["id"] = self.pubsub_item + mb_data = data_format.serialise(mb_data) + self.host.bridge.mbSend( self.pubsub_service, self.pubsub_node, mb_data, self.profile ) @@ -539,6 +547,7 @@ def getItemData(self, service, node, item): items = [item] if item is not None else [] mb_data = self.host.bridge.mbGet(service, node, 1, items, {}, self.profile)[0][0] + mb_data = data_format.deserialise(mb_data) try: content = mb_data["content_xhtml"] except KeyError: