Add way for report to provide available "choices" for any param

This commit is contained in:
Lance Edgar 2020-03-26 15:23:24 -05:00
parent a338d497e3
commit 76321e6fa6

View file

@ -97,6 +97,19 @@ class Report(object):
"""
return self.collect_static_params(**kwargs)
def get_choices(self, name, session):
"""
Invoke the appropriately-named method, to return a set of "choices" for
selection by the user. Note that ``name`` must correspond to one of
the parameter names.
"""
static_name = 'choices_{}'.format(name)
if hasattr(self, static_name):
return getattr(self, static_name)
getter = getattr(self, 'get_choices_{}'.format(name))
return getter(session)
def make_data(self, session, params, progress=None, **kwargs):
"""
Should generate and return a dict which contains all relevant data for
@ -139,7 +152,11 @@ class ReportParam(object):
Base class for report parameter definitions.
"""
# TODO: deprecate / remove the `typ` kwarg? (replace w/ `type`)
def __init__(self, typ=str, required=True, doc="", **kwargs):
if 'type' in kwargs:
self.type = kwargs.pop('type')
else:
self.type = typ
self.required = required
self.__doc__ == doc