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.
This commit is contained in:
Goffi 2019-02-23 18:59:00 +01:00
commit 512ae0b91e

View file

@ -142,9 +142,10 @@ class BlogPublishCommon(object):
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 @@ class Set(base.CommandBase, BlogPublishCommon):
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 @@ class Get(base.CommandBase):
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 @@ class Get(base.CommandBase):
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 @@ class Get(base.CommandBase):
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 @@ class Get(base.CommandBase):
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 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit):
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 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit):
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: