comparison frontends/src/jp/cmd_blog.py @ 2270:07caa12be945

jp (blog, common): added --force-item option to avoid magic and use argument as actual item id: - creation of new item with item id has been fixed - --force-item allow to use url as item id, or keyword - pubsub_item can is now returned by getItemPath. If not None, the id is known and must be used
author Goffi <goffi@goffi.org>
date Tue, 27 Jun 2017 17:00:52 +0200
parents 606ff34d30f2
children 2fae89f30b8d
comparison
equal deleted inserted replaced
2269:606ff34d30f2 2270:07caa12be945
299 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword")) 299 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword"))
300 self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel")) 300 self.parser.add_argument("-P", "--preview", action="store_true", help=_(u"launch a blog preview in parallel"))
301 self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item")) 301 self.parser.add_argument("-T", '--title', type=base.unicode_decoder, help=_(u"title of the item"))
302 self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item")) 302 self.parser.add_argument("-t", '--tag', type=base.unicode_decoder, action='append', help=_(u"tag (category) of your item"))
303 self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments")) 303 self.parser.add_argument("--no-comment", action='store_true', help=_(u"disable comments"))
304 common.BaseEdit.add_parser_options(self)
304 305
305 def buildMetadataFile(self, content_file_path, mb_data=None): 306 def buildMetadataFile(self, content_file_path, mb_data=None):
306 """Build a metadata file using json 307 """Build a metadata file using json
307 308
308 The file is named after content_file_path, with extension replaced by _metadata.json 309 The file is named after content_file_path, with extension replaced by _metadata.json
349 return mb_data, meta_file_path 350 return mb_data, meta_file_path
350 351
351 def edit(self, content_file_path, content_file_obj, 352 def edit(self, content_file_path, content_file_obj,
352 mb_data=None): 353 mb_data=None):
353 """Edit the file contening the content using editor, and publish it""" 354 """Edit the file contening the content using editor, and publish it"""
354 self.item_ori_mb_data = mb_data 355 if mb_data is not None:
356 self.pubsub_item = mb_data['id']
355 # we first create metadata file 357 # we first create metadata file
356 meta_ori, meta_file_path = self.buildMetadataFile(content_file_path, self.item_ori_mb_data) 358 meta_ori, meta_file_path = self.buildMetadataFile(content_file_path, mb_data)
357 359
358 # do we need a preview ? 360 # do we need a preview ?
359 if self.args.preview: 361 if self.args.preview:
360 self.disp(u"Preview requested, launching it", 1) 362 self.disp(u"Preview requested, launching it", 1)
361 # we redirect outputs to /dev/null to avoid console pollution in editor 363 # we redirect outputs to /dev/null to avoid console pollution in editor
367 self.runEditor("blog_editor_args", content_file_path, content_file_obj, meta_file_path=meta_file_path, meta_ori=meta_ori) 369 self.runEditor("blog_editor_args", content_file_path, content_file_obj, meta_file_path=meta_file_path, meta_ori=meta_ori)
368 370
369 def publish(self, content, mb_data): 371 def publish(self, content, mb_data):
370 mb_data['content_rich'] = content 372 mb_data['content_rich'] = content
371 373
372 if self.item_ori_mb_data is not None: 374 if self.pubsub_item is not None:
373 mb_data['id'] = self.item_ori_mb_data['id'] 375 mb_data['id'] = self.pubsub_item
374 376
375 self.host.bridge.mbSend(self.pubsub_service, self.pubsub_node, mb_data, self.profile) 377 self.host.bridge.mbSend(self.pubsub_service, self.pubsub_node, mb_data, self.profile)
376 self.disp(u"Blog item published") 378 self.disp(u"Blog item published")
377 379
378 def getTmpSuff(self): 380 def getTmpSuff(self):
396 def start(self): 398 def start(self):
397 # if there are user defined extension, we use them 399 # if there are user defined extension, we use them
398 SYNTAX_EXT.update(config.getConfig(self.sat_conf, 'jp', CONF_SYNTAX_EXT, {})) 400 SYNTAX_EXT.update(config.getConfig(self.sat_conf, 'jp', CONF_SYNTAX_EXT, {}))
399 self.current_syntax = None 401 self.current_syntax = None
400 402
401 self.pubsub_service, self.pubsub_node, content_file_path, content_file_obj, mb_data = self.getItemPath(self.args.item) 403 self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj, mb_data = self.getItemPath(self.args.item)
402 404
403 self.edit(content_file_path, content_file_obj, mb_data=mb_data) 405 self.edit(content_file_path, content_file_obj, mb_data=mb_data)
404 406
405 407
406 class Preview(base.CommandBase, BlogCommon): 408 class Preview(base.CommandBase, BlogCommon):