Expose params and type key for report output
This commit is contained in:
parent
118f22c164
commit
6ef217c546
|
@ -42,8 +42,9 @@ from rattail.threads import Thread
|
||||||
import colander
|
import colander
|
||||||
from mako.template import Template
|
from mako.template import Template
|
||||||
from pyramid.response import Response
|
from pyramid.response import Response
|
||||||
|
from webhelpers2.html import HTML
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms, grids
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views import View
|
from tailbone.views import View
|
||||||
from tailbone.views.exports import ExportMasterView
|
from tailbone.views.exports import ExportMasterView
|
||||||
|
@ -224,6 +225,8 @@ class ReportOutputView(ExportMasterView):
|
||||||
form_fields = [
|
form_fields = [
|
||||||
'id',
|
'id',
|
||||||
'report_name',
|
'report_name',
|
||||||
|
'report_type',
|
||||||
|
'params',
|
||||||
'filename',
|
'filename',
|
||||||
'created',
|
'created',
|
||||||
'created_by',
|
'created_by',
|
||||||
|
@ -235,9 +238,31 @@ class ReportOutputView(ExportMasterView):
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(ReportOutputView, self).configure_form(f)
|
super(ReportOutputView, self).configure_form(f)
|
||||||
|
|
||||||
|
# params
|
||||||
|
f.set_renderer('params', self.render_params)
|
||||||
|
|
||||||
|
# filename
|
||||||
if self.viewing:
|
if self.viewing:
|
||||||
f.set_renderer('filename', self.render_download)
|
f.set_renderer('filename', self.render_download)
|
||||||
|
|
||||||
|
def render_params(self, report, field):
|
||||||
|
params = report.params
|
||||||
|
if not params:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
# TODO: should sort these, perhaps according to Report definition?
|
||||||
|
params = [{'key': key, 'value': value}
|
||||||
|
for key, value in params.items()]
|
||||||
|
|
||||||
|
route_prefix = self.get_route_prefix()
|
||||||
|
g = grids.Grid(
|
||||||
|
key='{}.params'.format(route_prefix),
|
||||||
|
data=params,
|
||||||
|
columns=['key', 'value'],
|
||||||
|
)
|
||||||
|
return HTML.literal(g.render_grid())
|
||||||
|
|
||||||
def render_download(self, report, field):
|
def render_download(self, report, field):
|
||||||
path = report.filepath(self.rattail_config)
|
path = report.filepath(self.rattail_config)
|
||||||
url = self.get_action_url('download', report)
|
url = self.get_action_url('download', report)
|
||||||
|
|
Loading…
Reference in a new issue