Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
1904:614f3abb2c69 | 1905:e0bfdd379e8d |
---|---|
293 sat_conf = config.parseMainConf() | 293 sat_conf = config.parseMainConf() |
294 # if there are user defined extension, we use them | 294 # if there are user defined extension, we use them |
295 SYNTAX_EXT.update(config.getConfig(sat_conf, 'jp', CONF_SYNTAX_EXT, {})) | 295 SYNTAX_EXT.update(config.getConfig(sat_conf, 'jp', CONF_SYNTAX_EXT, {})) |
296 current_syntax = None | 296 current_syntax = None |
297 | 297 |
298 if item_lower == 'current': | 298 if item_lower in ('new', 'last'): |
299 # use wants to continue current draft | |
300 content_file_path = self.getCurrentFile(sat_conf) | |
301 content_file_obj = open(content_file_path, 'r+b') | |
302 current_syntax = self.guessSyntaxFromPath(sat_conf, content_file_path) | |
303 else: | |
304 # we get current syntax to determine file extension | 299 # we get current syntax to determine file extension |
305 current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) | 300 current_syntax = self.host.bridge.getParamA("Syntax", "Composition", "value", self.profile) |
306 # we now create a temporary file | 301 # we now create a temporary file |
307 tmp_suff = '.' + SYNTAX_EXT.get(current_syntax, SYNTAX_EXT['']) | 302 tmp_suff = '.' + SYNTAX_EXT.get(current_syntax, SYNTAX_EXT['']) |
308 content_file_obj, content_file_path = self.getTmpFile(sat_conf, tmp_suff) | 303 content_file_obj, content_file_path = self.getTmpFile(sat_conf, tmp_suff) |
304 if item_lower == 'new': | |
305 self.disp(u'Editing a new blog item', 2) | |
306 mb_data = None | |
307 elif item_lower == 'last': | |
308 self.disp(u'Editing last published item', 2) | |
309 try: | |
310 mb_data = self.host.bridge.mbGet('', '', 1, [], {}, self.profile)[0][0] | |
311 except Exception as e: | |
312 self.disp(u"Error while retrieving last item: {}".format(e)) | |
313 self.host.quit(1) | |
314 | |
315 content = mb_data['content_xhtml'] | |
316 if content and current_syntax != 'XHTML': | |
317 content = self.host.bridge.syntaxConvert(content, 'XHTML', current_syntax, False, self.profile) | |
318 content_file_obj.write(content.encode('utf-8')) | |
319 content_file_obj.seek(0) | |
320 else: | |
321 mb_data = None | |
322 if item_lower == 'current': | |
323 # use wants to continue current draft | |
324 content_file_path = self.getCurrentFile(sat_conf) | |
325 self.disp(u'Continuing edition of current draft', 2) | |
326 else: | |
327 # for now we taxe the item as a file path | |
328 content_file_path = os.path.expanduser(self.args.item) | |
329 content_file_obj = open(content_file_path, 'r+b') | |
330 current_syntax = self.guessSyntaxFromPath(sat_conf, content_file_path) | |
309 | 331 |
310 self.disp(u"Syntax used: {}".format(current_syntax), 1) | 332 self.disp(u"Syntax used: {}".format(current_syntax), 1) |
311 | |
312 if item_lower == 'new': | |
313 self.disp(u'Editing a new blog item', 2) | |
314 mb_data = None | |
315 elif item_lower == 'current': | |
316 self.disp(u'Continuing edition of current draft', 2) | |
317 mb_data = None | |
318 elif item_lower == 'last': | |
319 self.disp(u'Editing last published item', 2) | |
320 try: | |
321 mb_data = self.host.bridge.mbGet('', '', 1, [], {}, self.profile)[0][0] | |
322 except Exception as e: | |
323 self.disp(u"Error while retrieving last item: {}".format(e)) | |
324 self.host.quit(1) | |
325 | |
326 content = mb_data['content_xhtml'] | |
327 if content and current_syntax != 'XHTML': | |
328 content = self.host.bridge.syntaxConvert(content, 'XHTML', current_syntax, False, self.profile) | |
329 content_file_obj.write(content.encode('utf-8')) | |
330 content_file_obj.seek(0) | |
331 | |
332 self.edit(sat_conf, content_file_path, content_file_obj, mb_data=mb_data) | 333 self.edit(sat_conf, content_file_path, content_file_obj, mb_data=mb_data) |
333 | 334 |
334 | 335 |
335 class Preview(base.CommandBase, BlogCommon): | 336 class Preview(base.CommandBase, BlogCommon): |
336 | 337 |