Add way for report to provide available "choices" for any param
This commit is contained in:
parent
a338d497e3
commit
76321e6fa6
|
@ -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,8 +152,12 @@ 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):
|
||||
self.type = typ
|
||||
if 'type' in kwargs:
|
||||
self.type = kwargs.pop('type')
|
||||
else:
|
||||
self.type = typ
|
||||
self.required = required
|
||||
self.__doc__ == doc
|
||||
kwargs.pop('__doc__', None)
|
||||
|
|
Loading…
Reference in a new issue