From 5a4abbb1636a50eef16e959c0aab48f33b0412cf Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 7 Dec 2021 11:28:23 -0600 Subject: [PATCH] When viewing report output, show params as proper buefy table plus couple of other random tweaks --- .../templates/reports/generated/view.mako | 12 +++++++ tailbone/views/datasync.py | 7 +++- tailbone/views/reports.py | 34 +++++++++++++++++-- tailbone/views/stores.py | 1 + 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/tailbone/templates/reports/generated/view.mako b/tailbone/templates/reports/generated/view.mako index c7d34efa..ce8ef38d 100644 --- a/tailbone/templates/reports/generated/view.mako +++ b/tailbone/templates/reports/generated/view.mako @@ -8,4 +8,16 @@ % endif +<%def name="modify_this_page_vars()"> + ${parent.modify_this_page_vars()} + + + + ${parent.body()} diff --git a/tailbone/views/datasync.py b/tailbone/views/datasync.py index cff9553f..03be846e 100644 --- a/tailbone/views/datasync.py +++ b/tailbone/views/datasync.py @@ -224,7 +224,6 @@ class DataSyncChangeView(MasterView): url_prefix = '/datasync/changes' permission_prefix = 'datasync_changes' creatable = False - editable = False bulk_deletable = True labels = { @@ -256,6 +255,12 @@ class DataSyncChangeView(MasterView): kwargs['allow_filemon_restart'] = bool(self.rattail_config.get('tailbone', 'filemon.restart')) return kwargs + def configure_form(self, f): + super(DataSyncChangeView, self).configure_form(f) + + f.set_readonly('obtained') + + # TODO: deprecate / remove this DataSyncChangesView = DataSyncChangeView diff --git a/tailbone/views/reports.py b/tailbone/views/reports.py index 5d1ca5eb..204dc9df 100644 --- a/tailbone/views/reports.py +++ b/tailbone/views/reports.py @@ -45,7 +45,7 @@ from mako.template import Template from pyramid.response import Response from webhelpers2.html import HTML -from tailbone import forms, grids +from tailbone import forms from tailbone.db import Session from tailbone.views import View from tailbone.views.exports import ExportMasterView @@ -257,18 +257,39 @@ class ReportOutputView(ExportMasterView): params.sort(key=lambda param: param['key']) route_prefix = self.get_route_prefix() - g = grids.Grid( + factory = self.get_grid_factory() + g = factory( key='{}.params'.format(route_prefix), data=params, columns=['key', 'value'], + labels={'key': "Name"}, ) - return HTML.literal(g.render_grid()) + if self.get_use_buefy(): + return HTML.literal( + g.render_buefy_table_element(data_prop='paramsData')) + else: + return HTML.literal(g.render_grid()) def render_download(self, report, field): path = report.filepath(self.rattail_config) url = self.get_action_url('download', report) return self.render_file_field(path, url=url) + def template_kwargs_view(self, **kwargs): + use_buefy = self.get_use_buefy() + if use_buefy: + + report = kwargs['instance'] + params_data = [] + for name, value in report.params.items(): + params_data.append({ + 'name': name, + 'value': value, + }) + kwargs['params_data'] = params_data + + return kwargs + def download(self): report = self.get_instance() path = report.filepath(self.rattail_config) @@ -387,6 +408,13 @@ class GenerateReport(View): if param.type is datetime.date: form.set_type(param.name, 'date_jquery') + # auto-select default choice for fields which have only one + for param in report_params: + if param.type == 'choice' and param.required: + values = form.schema[param.name].widget.values + if len(values) == 1: + form.set_default(param.name, values[0][0]) + # if form validates, start generating new report output; show progress page if form.validate(newstyle=True): key = 'report_output.generate' diff --git a/tailbone/views/stores.py b/tailbone/views/stores.py index b3107a83..ef09e69b 100644 --- a/tailbone/views/stores.py +++ b/tailbone/views/stores.py @@ -42,6 +42,7 @@ class StoreView(MasterView): """ model_class = model.Store has_versions = True + touchable = True grid_columns = [ 'id',