comparison frontends/src/jp/common.py @ 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 276e546b7619
comparison
equal deleted inserted replaced
2279:e2f96cd1887b 2280:4bc9a2c2d6c9
329 self.disp(u"Could not find any content draft in {path}".format(path=tmp_dir), error=True) 329 self.disp(u"Could not find any content draft in {path}".format(path=tmp_dir), error=True)
330 self.host.quit(1) 330 self.host.quit(1)
331 return max(available, key=lambda path: os.stat(path).st_mtime) 331 return max(available, key=lambda path: os.stat(path).st_mtime)
332 332
333 def getItemData(self, service, node, item): 333 def getItemData(self, service, node, item):
334 """return formatted content and metadata (or not if use_metadata is false)""" 334 """return formatted content, metadata (or not if use_metadata is false), and item id"""
335 raise NotImplementedError 335 raise NotImplementedError
336 336
337 def getTmpSuff(self): 337 def getTmpSuff(self):
338 """return suffix used for content file""" 338 """return suffix used for content file"""
339 return u'xml' 339 return u'xml'
424 metadata = None 424 metadata = None
425 elif command in ('last', 'edit'): 425 elif command in ('last', 'edit'):
426 self.disp(u'Editing requested published item', 2) 426 self.disp(u'Editing requested published item', 2)
427 try: 427 try:
428 if self.use_metadata: 428 if self.use_metadata:
429 content, metadata = self.getItemData(pubsub_service, pubsub_node, pubsub_item) 429 content, metadata, pubsub_item = self.getItemData(pubsub_service, pubsub_node, pubsub_item)
430 else: 430 else:
431 content = self.getItemData(pubsub_service, pubsub_node, pubsub_item) 431 content, pubsub_item = self.getItemData(pubsub_service, pubsub_node, pubsub_item)
432 except Exception as e: 432 except Exception as e:
433 self.disp(u"Error while retrieving last item: {}".format(e)) 433 self.disp(u"Error while retrieving last item: {}".format(e))
434 self.host.quit(1) 434 self.host.quit(1)
435 content_file_obj.write(content.encode('utf-8')) 435 content_file_obj.write(content.encode('utf-8'))
436 content_file_obj.seek(0) 436 content_file_obj.seek(0)
453 pubsub_item = self.args.item 453 pubsub_item = self.args.item
454 454
455 try: 455 try:
456 # we try to get existing item 456 # we try to get existing item
457 if self.use_metadata: 457 if self.use_metadata:
458 content, metadata = self.getItemData(pubsub_service, pubsub_node, self.args.item) 458 content, metadata, pubsub_item = self.getItemData(pubsub_service, pubsub_node, self.args.item)
459 else: 459 else:
460 content = self.getItemData(pubsub_service, pubsub_node, self.args.item) 460 content, pubsub_item = self.getItemData(pubsub_service, pubsub_node, self.args.item)
461 except Exception as e: 461 except Exception as e:
462 # FIXME: ugly but we have not good may to check errors in bridge 462 # FIXME: ugly but we have not good may to check errors in bridge
463 if u'item-not-found' in unicode(e): 463 if u'item-not-found' in unicode(e):
464 # item doesn't exist, we create a new one with requested id 464 # item doesn't exist, we create a new one with requested id
465 metadata = None 465 metadata = None