Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/sat_frontends/jp/base.py Sun Jan 06 17:36:51 2019 +0100 +++ b/sat_frontends/jp/base.py Sun Jan 06 17:39:57 2019 +0100 @@ -375,6 +375,14 @@ if not flags.no_max: pubsub_group.add_argument("-m", "--max-items", dest="max", type=int, default=10, help=_(u"maximum number of items to get ({no_limit} to get all items)".format(no_limit=C.NO_LIMIT))) + # TODO: order-by should be a list to handle several levels of ordering + # but this is not yet done in SàT (and not really useful with + # current specifications, as only "creation" and "modification" are + # available) + pubsub_group.add_argument( + "-o", "--order-by", choices=[C.ORDER_BY_CREATION, + C.ORDER_BY_MODIFICATION], + help=_(u"how items should be ordered")) if not flags.all_used: raise exceptions.InternalError('unknown flags: {flags}'.format(flags=u', '.join(flags.unused))) @@ -979,6 +987,27 @@ self.disp(msg.format(failure_), error=True) self.host.quit(exit_code) + def getPubsubExtra(self, extra=None): + """Helper method to compute extra data from pubsub arguments + + @param extra(None, dict): base extra dict, or None to generate a new one + @return (dict): dict which can be used directly in the bridge for pubsub + """ + if extra is None: + extra = {} + else: + if {C.KEY_ORDER_BY}.intersection(extra.keys()): + raise exceptions.InternalError( + u"given extra dict has conflicting keys with pubsub keys") + try: + order_by = self.args.order_by + except AttributeError: + pass + else: + if order_by is not None: + extra[C.KEY_ORDER_BY] = self.args.order_by + return extra + def add_parser_options(self): try: subcommands = self.subcommands