jp (pubsub, common): fixed last item edition (keep item id instead of creating a new one)
This commit is contained in:
parent
c2ae6579c3
commit
364130bcbe
3 changed files with 8 additions and 9 deletions
|
|
@ -336,8 +336,6 @@ class Edit(base.CommandBase, BlogCommon, common.BaseEdit):
|
|||
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 @@ class Edit(base.CommandBase, BlogCommon, common.BaseEdit):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -331,12 +331,13 @@ class Edit(base.CommandBase, common.BaseEdit):
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ class BaseEdit(object):
|
|||
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 @@ class BaseEdit(object):
|
|||
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 @@ class BaseEdit(object):
|
|||
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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue