Refactor reports view to use master3

This commit is contained in:
Lance Edgar 2017-12-06 13:50:02 -06:00
parent 09ba419ee3
commit ef720e3a59

View file

@ -29,7 +29,6 @@ from __future__ import unicode_literals, absolute_import
import re import re
import rattail import rattail
from rattail import enum
from rattail.db import model from rattail.db import model
from rattail.files import resource_path from rattail.files import resource_path
from rattail.time import localtime from rattail.time import localtime
@ -37,7 +36,6 @@ from rattail.time import localtime
from mako.template import Template from mako.template import Template
from pyramid.response import Response from pyramid.response import Response
from tailbone import forms
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
@ -212,27 +210,27 @@ class ReportOutputView(ExportMasterView):
'created_by', 'created_by',
] ]
form_fields = [
'id',
'report_name',
'filename',
'created',
'created_by',
]
def configure_grid(self, g): def configure_grid(self, g):
super(ReportOutputView, self).configure_grid(g) super(ReportOutputView, self).configure_grid(g)
g.set_link('filename') g.set_link('filename')
def _preconfigure_fieldset(self, fs): def configure_form(self, f):
super(ReportOutputView, self)._preconfigure_fieldset(fs) super(ReportOutputView, self).configure_form(f)
if self.viewing: if self.viewing:
report = self.get_instance() f.set_renderer('filename', self.render_download)
download = forms.renderers.FileFieldRenderer.new(self,
storage_path=report.filepath(self.rattail_config, filename=None),
file_path=report.filepath(self.rattail_config))
fs.filename.set(renderer=download)
def configure_fieldset(self, fs): def render_download(self, report, field):
fs.configure(include=[ path = report.filepath(self.rattail_config)
fs.id, url = self.get_action_url('download', report)
fs.report_name, return self.render_file_field(path, url=url)
fs.filename,
fs.created,
fs.created_by,
])
def download(self): def download(self):
report = self.get_instance() report = self.get_instance()