Add way to quickly re-run "any" report

This commit is contained in:
Lance Edgar 2022-11-28 17:55:08 -06:00
parent 434633924a
commit b3bdee60bb
2 changed files with 42 additions and 2 deletions

View file

@ -1,6 +1,28 @@
## -*- coding: utf-8; -*- ## -*- coding: utf-8; -*-
<%inherit file="/master/view.mako" /> <%inherit file="/master/view.mako" />
<%def name="object_helpers()">
% if master.has_perm('create'):
<nav class="panel">
<p class="panel-heading">Tools</p>
<div class="panel-block buttons">
<div style="display: flex; flex-direction: column;">
<once-button type="is-primary"
% if rerun_report_url:
tag="a" href="${rerun_report_url}"
% else:
disabled title="Unknown report type"
% endif
text="Re-run This Report"
icon-pack="fas"
icon-left="arrow-circle-right">
</once-button>
</div>
</div>
</nav>
% endif
</%def>
<%def name="modify_this_page_vars()"> <%def name="modify_this_page_vars()">
${parent.modify_this_page_vars()} ${parent.modify_this_page_vars()}
<script type="text/javascript"> <script type="text/javascript">

View file

@ -316,10 +316,18 @@ class ReportOutputView(ExportMasterView):
def template_kwargs_view(self, **kwargs): def template_kwargs_view(self, **kwargs):
kwargs = super(ReportOutputView, self).template_kwargs_view(**kwargs) kwargs = super(ReportOutputView, self).template_kwargs_view(**kwargs)
output = kwargs['instance']
if self.get_use_buefy(): if self.get_use_buefy():
report = kwargs['instance'] kwargs['params_data'] = self.get_params_context(output)
kwargs['params_data'] = self.get_params_context(report)
# build custom URL to re-build this report
url = None
if output.report_type:
url = self.request.route_url('generate_specific_report',
type_key=output.report_type,
_query=output.params)
kwargs['rerun_report_url'] = url
return kwargs return kwargs
@ -386,6 +394,7 @@ class ReportOutputView(ExportMasterView):
input parameters specific to the report type, then creates a new report input parameters specific to the report type, then creates a new report
and redirects user to view the output. and redirects user to view the output.
""" """
app = self.get_rattail_app()
use_buefy = self.get_use_buefy() use_buefy = self.get_use_buefy()
type_key = self.request.matchdict['type_key'] type_key = self.request.matchdict['type_key']
report = self.report_handler.get_report(type_key) report = self.report_handler.get_report(type_key)
@ -445,6 +454,15 @@ class ReportOutputView(ExportMasterView):
if len(values) == 1: if len(values) == 1:
form.set_default(param.name, values[0][0]) form.set_default(param.name, values[0][0])
# set default field values according to query string, if applicable
if self.request.GET:
for param in report_params:
if param.name in self.request.GET:
value = self.request.GET[param.name]
if param.type is datetime.date:
value = app.parse_date(value)
form.set_default(param.name, value)
# if form validates, start generating new report output; show progress page # if form validates, start generating new report output; show progress page
if form.validate(newstyle=True): if form.validate(newstyle=True):
key = 'report_output.generate' key = 'report_output.generate'