Mercurial > libervia-backend
diff frontends/src/jp/cmd_blog.py @ 1905:e0bfdd379e8d
jp (blog/edit): a draft file can be directly specified
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 10 Mar 2016 18:05:37 +0100 |
parents | 614f3abb2c69 |
children | 58f25b274536 |
line wrap: on
line diff
--- a/frontends/src/jp/cmd_blog.py Thu Mar 10 17:50:17 2016 +0100 +++ b/frontends/src/jp/cmd_blog.py Thu Mar 10 18:05:37 2016 +0100 @@ -295,40 +295,41 @@ SYNTAX_EXT.update(config.getConfig(sat_conf, 'jp', CONF_SYNTAX_EXT, {})) current_syntax = None - if item_lower == 'current': - # use wants to continue current draft - content_file_path = self.getCurrentFile(sat_conf) - content_file_obj = open(content_file_path, 'r+b') - current_syntax = self.guessSyntaxFromPath(sat_conf, content_file_path) - else: + if item_lower in ('new', 'last'): # we get current syntax to determine file extension current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) # we now create a temporary file tmp_suff = '.' + SYNTAX_EXT.get(current_syntax, SYNTAX_EXT['']) content_file_obj, content_file_path = self.getTmpFile(sat_conf, tmp_suff) + if item_lower == 'new': + self.disp(u'Editing a new blog item', 2) + mb_data = None + elif item_lower == 'last': + self.disp(u'Editing last published item', 2) + try: + mb_data = self.host.bridge.mbGet('', '', 1, [], {}, self.profile)[0][0] + except Exception as e: + self.disp(u"Error while retrieving last item: {}".format(e)) + self.host.quit(1) + + content = mb_data['content_xhtml'] + if content and current_syntax != 'XHTML': + content = self.host.bridge.syntaxConvert(content, 'XHTML', current_syntax, False, self.profile) + content_file_obj.write(content.encode('utf-8')) + content_file_obj.seek(0) + else: + mb_data = None + if item_lower == 'current': + # use wants to continue current draft + content_file_path = self.getCurrentFile(sat_conf) + self.disp(u'Continuing edition of current draft', 2) + else: + # for now we taxe the item as a file path + content_file_path = os.path.expanduser(self.args.item) + content_file_obj = open(content_file_path, 'r+b') + current_syntax = self.guessSyntaxFromPath(sat_conf, content_file_path) self.disp(u"Syntax used: {}".format(current_syntax), 1) - - if item_lower == 'new': - self.disp(u'Editing a new blog item', 2) - mb_data = None - elif item_lower == 'current': - self.disp(u'Continuing edition of current draft', 2) - mb_data = None - elif item_lower == 'last': - self.disp(u'Editing last published item', 2) - try: - mb_data = self.host.bridge.mbGet('', '', 1, [], {}, self.profile)[0][0] - except Exception as e: - self.disp(u"Error while retrieving last item: {}".format(e)) - self.host.quit(1) - - content = mb_data['content_xhtml'] - if content and current_syntax != 'XHTML': - content = self.host.bridge.syntaxConvert(content, 'XHTML', current_syntax, False, self.profile) - content_file_obj.write(content.encode('utf-8')) - content_file_obj.seek(0) - self.edit(sat_conf, content_file_path, content_file_obj, mb_data=mb_data)