Mercurial > libervia-backend
comparison sat_frontends/jp/base.py @ 2761:4b693ea24d5f
jp (base, pubsub, ticket): handle order-by:
--order-by has been added to pubsub group.
New getPubsubExtra helper method generate extra dict according to arguments.
getPubsubExtra is used for pubsub/get, blog/get and and ticket/get.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 06 Jan 2019 17:39:57 +0100 |
parents | bad70aa70c87 |
children | 92af49cde255 |
comparison
equal
deleted
inserted
replaced
2760:3480d4fdf83a | 2761:4b693ea24d5f |
---|---|
373 # mutiple items | 373 # mutiple items |
374 pubsub_group.add_argument("-i", "--item", type=unicode_decoder, action='append', dest='items', default=[], help=_(u"items to retrieve (DEFAULT: all)")) | 374 pubsub_group.add_argument("-i", "--item", type=unicode_decoder, action='append', dest='items', default=[], help=_(u"items to retrieve (DEFAULT: all)")) |
375 if not flags.no_max: | 375 if not flags.no_max: |
376 pubsub_group.add_argument("-m", "--max-items", dest="max", type=int, default=10, | 376 pubsub_group.add_argument("-m", "--max-items", dest="max", type=int, default=10, |
377 help=_(u"maximum number of items to get ({no_limit} to get all items)".format(no_limit=C.NO_LIMIT))) | 377 help=_(u"maximum number of items to get ({no_limit} to get all items)".format(no_limit=C.NO_LIMIT))) |
378 # TODO: order-by should be a list to handle several levels of ordering | |
379 # but this is not yet done in SàT (and not really useful with | |
380 # current specifications, as only "creation" and "modification" are | |
381 # available) | |
382 pubsub_group.add_argument( | |
383 "-o", "--order-by", choices=[C.ORDER_BY_CREATION, | |
384 C.ORDER_BY_MODIFICATION], | |
385 help=_(u"how items should be ordered")) | |
378 | 386 |
379 if not flags.all_used: | 387 if not flags.all_used: |
380 raise exceptions.InternalError('unknown flags: {flags}'.format(flags=u', '.join(flags.unused))) | 388 raise exceptions.InternalError('unknown flags: {flags}'.format(flags=u', '.join(flags.unused))) |
381 if defaults: | 389 if defaults: |
382 raise exceptions.InternalError('unused defaults: {defaults}'.format(defaults=defaults)) | 390 raise exceptions.InternalError('unused defaults: {defaults}'.format(defaults=defaults)) |
977 if msg is None: | 985 if msg is None: |
978 msg = _(u"error: {}") | 986 msg = _(u"error: {}") |
979 self.disp(msg.format(failure_), error=True) | 987 self.disp(msg.format(failure_), error=True) |
980 self.host.quit(exit_code) | 988 self.host.quit(exit_code) |
981 | 989 |
990 def getPubsubExtra(self, extra=None): | |
991 """Helper method to compute extra data from pubsub arguments | |
992 | |
993 @param extra(None, dict): base extra dict, or None to generate a new one | |
994 @return (dict): dict which can be used directly in the bridge for pubsub | |
995 """ | |
996 if extra is None: | |
997 extra = {} | |
998 else: | |
999 if {C.KEY_ORDER_BY}.intersection(extra.keys()): | |
1000 raise exceptions.InternalError( | |
1001 u"given extra dict has conflicting keys with pubsub keys") | |
1002 try: | |
1003 order_by = self.args.order_by | |
1004 except AttributeError: | |
1005 pass | |
1006 else: | |
1007 if order_by is not None: | |
1008 extra[C.KEY_ORDER_BY] = self.args.order_by | |
1009 return extra | |
1010 | |
982 def add_parser_options(self): | 1011 def add_parser_options(self): |
983 try: | 1012 try: |
984 subcommands = self.subcommands | 1013 subcommands = self.subcommands |
985 except AttributeError: | 1014 except AttributeError: |
986 # We don't have subcommands, the class need to implements add_parser_options | 1015 # We don't have subcommands, the class need to implements add_parser_options |