changeset 2280:4bc9a2c2d6c9

jp (pubsub, common): fixed last item edition (keep item id instead of creating a new one)
author Goffi <goffi@goffi.org>
date Wed, 28 Jun 2017 20:28:24 +0200
parents e2f96cd1887b
children 4af1805cc6df
files frontends/src/jp/cmd_blog.py frontends/src/jp/cmd_pubsub.py frontends/src/jp/common.py
diffstat 3 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_blog.py	Wed Jun 28 19:19:08 2017 +0200
+++ b/frontends/src/jp/cmd_blog.py	Wed Jun 28 20:28:24 2017 +0200
@@ -336,8 +336,6 @@
     def edit(self, content_file_path, content_file_obj,
              mb_data=None):
         """Edit the file contening the content using editor, and publish it"""
-        if mb_data is not None:
-            self.pubsub_item = mb_data['id']
         # we first create metadata file
         meta_ori, meta_file_path = self.buildMetadataFile(content_file_path, mb_data)
 
@@ -377,7 +375,7 @@
                 content = self.host.bridge.syntaxConvert(content, 'text', 'XHTML', False, self.profile)
         if content and self.current_syntax != 'XHTML':
             content = self.host.bridge.syntaxConvert(content, 'XHTML', self.current_syntax, False, self.profile)
-        return content, mb_data
+        return content, mb_data, mb_data['id']
 
     def start(self):
         # if there are user defined extension, we use them
--- a/frontends/src/jp/cmd_pubsub.py	Wed Jun 28 19:19:08 2017 +0200
+++ b/frontends/src/jp/cmd_pubsub.py	Wed Jun 28 20:28:24 2017 +0200
@@ -331,12 +331,13 @@
         item_raw =  self.host.bridge.psItemsGet(service, node, 1, items, "", {}, self.profile)[0][0]
         parser = etree.XMLParser(remove_blank_text=True)
         item_elt = etree.fromstring(item_raw, parser)
+        item_id = item_elt.get('id')
         try:
             payload = item_elt[0]
         except IndexError:
             self.disp(_(u'Item has not payload'), 1)
             return  u''
-        return etree.tostring(payload, encoding="unicode", pretty_print=True)
+        return etree.tostring(payload, encoding="unicode", pretty_print=True), item_id
 
     def start(self):
         self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj = self.getItemPath(self.args.item)
--- a/frontends/src/jp/common.py	Wed Jun 28 19:19:08 2017 +0200
+++ b/frontends/src/jp/common.py	Wed Jun 28 20:28:24 2017 +0200
@@ -331,7 +331,7 @@
         return max(available, key=lambda path: os.stat(path).st_mtime)
 
     def getItemData(self, service, node, item):
-        """return formatted content and metadata (or not if use_metadata is false)"""
+        """return formatted content, metadata (or not if use_metadata is false), and item id"""
         raise NotImplementedError
 
     def getTmpSuff(self):
@@ -426,9 +426,9 @@
                 self.disp(u'Editing requested published item', 2)
                 try:
                     if self.use_metadata:
-                        content, metadata = self.getItemData(pubsub_service, pubsub_node, pubsub_item)
+                        content, metadata, pubsub_item = self.getItemData(pubsub_service, pubsub_node, pubsub_item)
                     else:
-                        content = self.getItemData(pubsub_service, pubsub_node, pubsub_item)
+                        content, pubsub_item = self.getItemData(pubsub_service, pubsub_node, pubsub_item)
                 except Exception as e:
                     self.disp(u"Error while retrieving last item: {}".format(e))
                     self.host.quit(1)
@@ -455,9 +455,9 @@
                 try:
                     # we try to get existing item
                     if self.use_metadata:
-                        content, metadata = self.getItemData(pubsub_service, pubsub_node, self.args.item)
+                        content, metadata, pubsub_item = self.getItemData(pubsub_service, pubsub_node, self.args.item)
                     else:
-                        content = self.getItemData(pubsub_service, pubsub_node, self.args.item)
+                        content, pubsub_item = self.getItemData(pubsub_service, pubsub_node, self.args.item)
                 except Exception as e:
                     # FIXME: ugly but we have not good may to check errors in bridge
                     if u'item-not-found' in unicode(e):