Mercurial > libervia-backend
comparison frontends/src/jp/common.py @ 2276:5cd45a79775b
jp (common): added --last-item to take last item when no item id is found/given
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2017 01:20:44 +0200 |
parents | 5f0dbf42aa9c |
children | e2f96cd1887b |
comparison
equal
deleted
inserted
replaced
2275:64e99bf0dfa2 | 2276:5cd45a79775b |
---|---|
101 self.sat_conf = config.parseMainConf() | 101 self.sat_conf = config.parseMainConf() |
102 self.cat_dir_str = cat_dir.encode('utf-8') | 102 self.cat_dir_str = cat_dir.encode('utf-8') |
103 self.use_metadata = use_metadata | 103 self.use_metadata = use_metadata |
104 | 104 |
105 def add_parser_options(self): | 105 def add_parser_options(self): |
106 self.parser.add_argument("--force-item", action='store_true', help=_(u"don't use magic and take item argument as an actual item")) | 106 group = self.parser.add_mutually_exclusive_group() |
107 group.add_argument("--force-item", action='store_true', help=_(u"don't use magic and take item argument as an actual item")) | |
108 group.add_argument("--last-item", action='store_true', help=_(u"take last item instead of creating a new one if no item id is found")) | |
107 | 109 |
108 def secureUnlink(self, path): | 110 def secureUnlink(self, path): |
109 """Unlink given path after keeping it for a while | 111 """Unlink given path after keeping it for a while |
110 | 112 |
111 This method is used to prevent accidental deletion of a draft | 113 This method is used to prevent accidental deletion of a draft |
373 pubsub_node = pubsub_data['node'][0] | 375 pubsub_node = pubsub_data['node'][0] |
374 except KeyError: | 376 except KeyError: |
375 self.disp(u'No node found in xmpp: URI, can\'t retrieve item', error=True) | 377 self.disp(u'No node found in xmpp: URI, can\'t retrieve item', error=True) |
376 self.host.quit(1) | 378 self.host.quit(1) |
377 pubsub_item = pubsub_data.get('item',[None])[0] | 379 pubsub_item = pubsub_data.get('item',[None])[0] |
378 if pubsub_item is not None: | 380 if pubsub_item is None and self.args.last_item: |
381 command = 'last' | |
382 elif pubsub_item is not None: | |
379 command = 'edit' # XXX: edit command is only used internaly, it similar to last, but with the item given in the URL | 383 command = 'edit' # XXX: edit command is only used internaly, it similar to last, but with the item given in the URL |
380 else: | 384 else: |
381 command = 'new' | 385 command = 'new' |
386 | |
387 if self.args.last_item and command != 'last': | |
388 self.parser.error(_(u"--last-item can't be used with a specified item")) | |
382 | 389 |
383 if not force_item and command in ('new', 'last', 'edit'): | 390 if not force_item and command in ('new', 'last', 'edit'): |
384 # we need a temporary file | 391 # we need a temporary file |
385 tmp_suff = '.' + self.getTmpSuff() | 392 tmp_suff = '.' + self.getTmpSuff() |
386 content_file_obj, content_file_path = self.getTmpFile(tmp_suff) | 393 content_file_obj, content_file_path = self.getTmpFile(tmp_suff) |