Sort available reports by name, if handler doesn't specify

also add basic support for "decimal" params
This commit is contained in:
Lance Edgar 2020-05-19 12:42:07 -05:00
parent 2139fea3d0
commit b5f9c8e358
2 changed files with 10 additions and 3 deletions

View file

@ -97,7 +97,8 @@
<p>Please select the type of report you wish to generate.</p> <p>Please select the type of report you wish to generate.</p>
<div class="report-selection"> <div class="report-selection">
% for key, report in reports.items(): % for key in sorted_reports:
<% report = reports[key] %>
<h3>${h.link_to(report.name, url('generate_specific_report', type_key=key))}</h3> <h3>${h.link_to(report.name, url('generate_specific_report', type_key=key))}</h3>
<p>${report.__doc__}</p> <p>${report.__doc__}</p>
% endfor % endfor

View file

@ -38,7 +38,7 @@ from rattail.files import resource_path
from rattail.time import localtime from rattail.time import localtime
from rattail.reporting import get_report_handler from rattail.reporting import get_report_handler
from rattail.threads import Thread from rattail.threads import Thread
from rattail.util import simple_error from rattail.util import simple_error, OrderedDict
import colander import colander
from deform import widget as dfwidget from deform import widget as dfwidget
@ -297,9 +297,13 @@ class GenerateReport(View):
# handler is responsible for determining which report types are valid # handler is responsible for determining which report types are valid
reports = self.handler.get_reports() reports = self.handler.get_reports()
if isinstance(reports, OrderedDict):
sorted_reports = list(reports)
else:
sorted_reports = sorted(reports, key=lambda k: reports[k].name)
# make form to accept user choice of report type # make form to accept user choice of report type
schema = NewReport().bind(valid_report_types=list(reports)) schema = NewReport().bind(valid_report_types=sorted_reports)
form = forms.Form(schema=schema, request=self.request, use_buefy=use_buefy) form = forms.Form(schema=schema, request=self.request, use_buefy=use_buefy)
form.submit_label = "Continue" form.submit_label = "Continue"
form.cancel_url = self.request.route_url('report_output') form.cancel_url = self.request.route_url('report_output')
@ -325,6 +329,7 @@ class GenerateReport(View):
'form': form, 'form': form,
'dform': form.make_deform_form(), 'dform': form.make_deform_form(),
'reports': reports, 'reports': reports,
'sorted_reports': sorted_reports,
'report_descriptions': dict([(r.type_key, r.__doc__) 'report_descriptions': dict([(r.type_key, r.__doc__)
for r in reports.values()]), for r in reports.values()]),
'use_form': self.rattail_config.getbool('tailbone', 'reporting.choosing_uses_form', 'use_form': self.rattail_config.getbool('tailbone', 'reporting.choosing_uses_form',
@ -346,6 +351,7 @@ class GenerateReport(View):
NODE_TYPES = { NODE_TYPES = {
bool: colander.Boolean, bool: colander.Boolean,
datetime.date: colander.Date, datetime.date: colander.Date,
'decimal': colander.Decimal,
} }
schema = colander.Schema() schema = colander.Schema()