diff --git a/tailbone/views/reports.py b/tailbone/views/reports.py index 7fbdde03..ace0a7aa 100644 --- a/tailbone/views/reports.py +++ b/tailbone/views/reports.py @@ -41,6 +41,7 @@ from rattail.threads import Thread from rattail.util import simple_error import colander +from deform import widget as dfwidget from mako.template import Template from pyramid.response import Response from webhelpers2.html import HTML @@ -251,9 +252,10 @@ class ReportOutputView(ExportMasterView): if not params: return "" - # TODO: should sort these, perhaps according to Report definition? params = [{'key': key, 'value': value} for key, value in params.items()] + # TODO: should sort these according to true Report definition instead? + params.sort(key=lambda param: param['key']) route_prefix = self.get_route_prefix() g = grids.Grid( @@ -342,6 +344,7 @@ class GenerateReport(View): report_params = report.make_params(Session()) NODE_TYPES = { + bool: colander.Boolean, datetime.date: colander.Date, } @@ -352,10 +355,19 @@ class GenerateReport(View): node_type = NODE_TYPES.get(param.type, colander.String) node = colander.SchemaNode(typ=node_type(), name=param.name) + # maybe setup choices, if appropriate + if param.type == 'choice': + node.widget = dfwidget.SelectWidget( + values=report.get_choices(param.name, Session())) + # allow empty value if param is optional if not param.required: node.missing = colander.null + # maybe set default value + if hasattr(param, 'default'): + node.default = param.default + schema.add(node) form = forms.Form(schema=schema, request=self.request,