Make "generate report" the same as "create new generated report"
no reason to reinvent that wheel
This commit is contained in:
parent
d677cb1bc8
commit
b22e7fd077
|
@ -1,9 +1,5 @@
|
||||||
## -*- coding: utf-8; -*-
|
## -*- coding: utf-8; -*-
|
||||||
<%inherit file="/form.mako" />
|
<%inherit file="/master/create.mako" />
|
||||||
|
|
||||||
<%def name="title()">${index_title}</%def>
|
|
||||||
|
|
||||||
<%def name="content_title()"></%def>
|
|
||||||
|
|
||||||
<%def name="extra_javascript()">
|
<%def name="extra_javascript()">
|
||||||
${parent.extra_javascript()}
|
${parent.extra_javascript()}
|
||||||
|
@ -60,12 +56,6 @@
|
||||||
</style>
|
</style>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
|
||||||
% if request.has_perm('report_output.list'):
|
|
||||||
${h.link_to("View Generated Reports", url('report_output'))}
|
|
||||||
% endif
|
|
||||||
</%def>
|
|
||||||
|
|
||||||
<%def name="render_buefy_form()">
|
<%def name="render_buefy_form()">
|
||||||
<div class="form">
|
<div class="form">
|
||||||
<p>Please select the type of report you wish to generate.</p>
|
<p>Please select the type of report you wish to generate.</p>
|
|
@ -1,15 +1,9 @@
|
||||||
## -*- coding: utf-8; -*-
|
## -*- coding: utf-8; -*-
|
||||||
<%inherit file="/form.mako" />
|
<%inherit file="/master/form.mako" />
|
||||||
|
|
||||||
<%def name="title()">${index_title} » ${report.name}</%def>
|
<%def name="title()">${index_title} » ${report.name}</%def>
|
||||||
|
|
||||||
<%def name="content_title()">${report.name}</%def>
|
<%def name="content_title()">New Report: ${report.name}</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
|
||||||
% if request.has_perm('report_output.list'):
|
|
||||||
${h.link_to("View Generated Reports", url('report_output'))}
|
|
||||||
% endif
|
|
||||||
</%def>
|
|
||||||
|
|
||||||
<%def name="render_buefy_form()">
|
<%def name="render_buefy_form()">
|
||||||
<div class="form">
|
<div class="form">
|
|
@ -1,11 +0,0 @@
|
||||||
## -*- coding: utf-8; -*-
|
|
||||||
<%inherit file="/master/index.mako" />
|
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
|
||||||
${parent.context_menu_items()}
|
|
||||||
% if request.has_perm('{}.generate'.format(permission_prefix)):
|
|
||||||
<li>${h.link_to("Generate new Report", url('generate_report'))}</li>
|
|
||||||
% endif
|
|
||||||
</%def>
|
|
||||||
|
|
||||||
${parent.body()}
|
|
|
@ -1,13 +1,6 @@
|
||||||
## -*- coding: utf-8; -*-
|
## -*- coding: utf-8; -*-
|
||||||
<%inherit file="/master/view.mako" />
|
<%inherit file="/master/view.mako" />
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
|
||||||
${parent.context_menu_items()}
|
|
||||||
% if request.has_perm('{}.generate'.format(permission_prefix)):
|
|
||||||
<li>${h.link_to("Generate new Report", url('generate_report'))}</li>
|
|
||||||
% 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">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2019 Lance Edgar
|
# Copyright © 2010-2022 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -148,12 +148,6 @@ class ExportMasterView(MasterView):
|
||||||
obj.created_by = self.request.user
|
obj.created_by = self.request.user
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def render_download(self, export, field):
|
|
||||||
path = self.get_file_path(export)
|
|
||||||
text = "{} ({})".format(export.filename, self.readable_size(path))
|
|
||||||
url = self.request.route_url('{}.download'.format(self.get_route_prefix()), uuid=export.uuid)
|
|
||||||
return tags.link_to(text, url)
|
|
||||||
|
|
||||||
def render_created_by(self, export, field):
|
def render_created_by(self, export, field):
|
||||||
user = export.created_by
|
user = export.created_by
|
||||||
if not user:
|
if not user:
|
||||||
|
|
|
@ -212,6 +212,7 @@ class ReportOutputView(ExportMasterView):
|
||||||
model_class = model.ReportOutput
|
model_class = model.ReportOutput
|
||||||
route_prefix = 'report_output'
|
route_prefix = 'report_output'
|
||||||
url_prefix = '/reports/generated'
|
url_prefix = '/reports/generated'
|
||||||
|
creatable = True
|
||||||
downloadable = True
|
downloadable = True
|
||||||
configurable = True
|
configurable = True
|
||||||
config_title = "Reporting"
|
config_title = "Reporting"
|
||||||
|
@ -235,6 +236,14 @@ class ReportOutputView(ExportMasterView):
|
||||||
'created_by',
|
'created_by',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __init__(self, request):
|
||||||
|
super(ReportOutputView, self).__init__(request)
|
||||||
|
self.report_handler = self.get_report_handler()
|
||||||
|
|
||||||
|
def get_report_handler(self):
|
||||||
|
app = self.get_rattail_app()
|
||||||
|
return app.get_report_handler()
|
||||||
|
|
||||||
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')
|
||||||
|
@ -245,10 +254,6 @@ class ReportOutputView(ExportMasterView):
|
||||||
# params
|
# params
|
||||||
f.set_renderer('params', self.render_params)
|
f.set_renderer('params', self.render_params)
|
||||||
|
|
||||||
# filename
|
|
||||||
if self.viewing:
|
|
||||||
f.set_renderer('filename', self.render_download)
|
|
||||||
|
|
||||||
def render_params(self, report, field):
|
def render_params(self, report, field):
|
||||||
params = report.params
|
params = report.params
|
||||||
if not params:
|
if not params:
|
||||||
|
@ -273,11 +278,6 @@ class ReportOutputView(ExportMasterView):
|
||||||
else:
|
else:
|
||||||
return HTML.literal(g.render_grid())
|
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 get_params_context(self, report):
|
def get_params_context(self, report):
|
||||||
params_data = []
|
params_data = []
|
||||||
for name, value in (report.params or {}).items():
|
for name, value in (report.params or {}).items():
|
||||||
|
@ -305,36 +305,7 @@ class ReportOutputView(ExportMasterView):
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def download(self):
|
def create(self):
|
||||||
report = self.get_instance()
|
|
||||||
path = report.filepath(self.rattail_config)
|
|
||||||
return self.file_response(path)
|
|
||||||
|
|
||||||
def configure_get_simple_settings(self):
|
|
||||||
config = self.rattail_config
|
|
||||||
return [
|
|
||||||
|
|
||||||
# generating
|
|
||||||
{'section': 'tailbone',
|
|
||||||
'option': 'reporting.choosing_uses_form',
|
|
||||||
'type': bool},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class GenerateReport(View):
|
|
||||||
"""
|
|
||||||
View for generating a new report.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, request):
|
|
||||||
super(GenerateReport, self).__init__(request)
|
|
||||||
self.handler = self.get_handler()
|
|
||||||
|
|
||||||
def get_handler(self):
|
|
||||||
app = self.get_rattail_app()
|
|
||||||
return app.get_report_handler()
|
|
||||||
|
|
||||||
def choose(self):
|
|
||||||
"""
|
"""
|
||||||
View which allows user to choose which type of report they wish to
|
View which allows user to choose which type of report they wish to
|
||||||
generate.
|
generate.
|
||||||
|
@ -342,7 +313,7 @@ class GenerateReport(View):
|
||||||
use_buefy = self.get_use_buefy()
|
use_buefy = self.get_use_buefy()
|
||||||
|
|
||||||
# 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.report_handler.get_reports()
|
||||||
if isinstance(reports, OrderedDict):
|
if isinstance(reports, OrderedDict):
|
||||||
sorted_reports = list(reports)
|
sorted_reports = list(reports)
|
||||||
else:
|
else:
|
||||||
|
@ -370,18 +341,17 @@ class GenerateReport(View):
|
||||||
raise self.redirect(self.request.route_url('generate_specific_report',
|
raise self.redirect(self.request.route_url('generate_specific_report',
|
||||||
type_key=form.validated['report_type']))
|
type_key=form.validated['report_type']))
|
||||||
|
|
||||||
return {
|
return self.render_to_response('choose', {
|
||||||
'index_title': "Generate Report",
|
|
||||||
'form': form,
|
'form': form,
|
||||||
'dform': form.make_deform_form(),
|
'dform': form.make_deform_form(),
|
||||||
'reports': reports,
|
'reports': reports,
|
||||||
'sorted_reports': sorted_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(
|
||||||
default=True),
|
'tailbone', 'reporting.choosing_uses_form',
|
||||||
'use_buefy': use_buefy,
|
default=True),
|
||||||
}
|
})
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
"""
|
"""
|
||||||
|
@ -391,8 +361,9 @@ class GenerateReport(View):
|
||||||
"""
|
"""
|
||||||
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.handler.get_report(type_key)
|
report = self.report_handler.get_report(type_key)
|
||||||
report_params = report.make_params(Session())
|
report_params = report.make_params(Session())
|
||||||
|
route_prefix = self.get_route_prefix()
|
||||||
|
|
||||||
NODE_TYPES = {
|
NODE_TYPES = {
|
||||||
bool: colander.Boolean,
|
bool: colander.Boolean,
|
||||||
|
@ -429,7 +400,7 @@ class GenerateReport(View):
|
||||||
form = forms.Form(schema=schema, request=self.request,
|
form = forms.Form(schema=schema, request=self.request,
|
||||||
use_buefy=use_buefy, helptext=helptext)
|
use_buefy=use_buefy, helptext=helptext)
|
||||||
form.submit_label = "Generate this Report"
|
form.submit_label = "Generate this Report"
|
||||||
form.cancel_url = self.request.route_url('generate_report')
|
form.cancel_url = self.request.route_url('{}.create'.format(route_prefix))
|
||||||
|
|
||||||
# must declare jquery support for date fields, ugh
|
# must declare jquery support for date fields, ugh
|
||||||
# TODO: obviously would be nice for this to be automatic?
|
# TODO: obviously would be nice for this to be automatic?
|
||||||
|
@ -458,14 +429,16 @@ class GenerateReport(View):
|
||||||
'cancel_msg': "Report generation was canceled",
|
'cancel_msg': "Report generation was canceled",
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
# hide the "Create New" button for this page, b/c user is
|
||||||
'index_title': "Generate Report",
|
# already in the process of creating new..
|
||||||
'index_url': self.request.route_url('generate_report'),
|
# TODO: this seems hacky, but works
|
||||||
|
self.show_create_link = False
|
||||||
|
|
||||||
|
return self.render_to_response('generate', {
|
||||||
'report': report,
|
'report': report,
|
||||||
'form': form,
|
'form': form,
|
||||||
'dform': form.make_deform_form(),
|
'dform': form.make_deform_form(),
|
||||||
'use_buefy': self.get_use_buefy(),
|
})
|
||||||
}
|
|
||||||
|
|
||||||
def generate_thread(self, report, params, user_uuid, progress=None):
|
def generate_thread(self, report, params, user_uuid, progress=None):
|
||||||
"""
|
"""
|
||||||
|
@ -476,7 +449,7 @@ class GenerateReport(View):
|
||||||
session = RattailSession()
|
session = RattailSession()
|
||||||
user = session.query(model.User).get(user_uuid)
|
user = session.query(model.User).get(user_uuid)
|
||||||
try:
|
try:
|
||||||
output = self.handler.generate_output(session, report, params, user, progress=progress)
|
output = self.report_handler.generate_output(session, report, params, user, progress=progress)
|
||||||
|
|
||||||
# if anything goes wrong, rollback and log the error etc.
|
# if anything goes wrong, rollback and log the error etc.
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
@ -501,24 +474,36 @@ class GenerateReport(View):
|
||||||
progress.session['success_url'] = success_url
|
progress.session['success_url'] = success_url
|
||||||
progress.session.save()
|
progress.session.save()
|
||||||
|
|
||||||
|
def download(self):
|
||||||
|
report = self.get_instance()
|
||||||
|
path = report.filepath(self.rattail_config)
|
||||||
|
return self.file_response(path)
|
||||||
|
|
||||||
|
def configure_get_simple_settings(self):
|
||||||
|
config = self.rattail_config
|
||||||
|
return [
|
||||||
|
|
||||||
|
# generating
|
||||||
|
{'section': 'tailbone',
|
||||||
|
'option': 'reporting.choosing_uses_form',
|
||||||
|
'type': bool},
|
||||||
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def defaults(cls, config):
|
def defaults(cls, config):
|
||||||
|
cls._defaults(config)
|
||||||
|
cls._report_output_defaults(config)
|
||||||
|
|
||||||
# note that we include this in the "Generated Reports" permissions group
|
@classmethod
|
||||||
config.add_tailbone_permission('report_output', 'report_output.generate',
|
def _report_output_defaults(cls, config):
|
||||||
"Generate new report (of any type)")
|
url_prefix = cls.get_url_prefix()
|
||||||
|
permission_prefix = cls.get_permission_prefix()
|
||||||
|
|
||||||
# "generate report" (which is really "choose")
|
# generate report (accept custom params, truly create)
|
||||||
config.add_route('generate_report', '/reports/generate')
|
config.add_route('generate_specific_report',
|
||||||
config.add_view(cls, attr='choose', route_name='generate_report',
|
'{}/new/{{type_key}}'.format(url_prefix))
|
||||||
permission='report_output.generate',
|
|
||||||
renderer='/reports/choose.mako')
|
|
||||||
|
|
||||||
# "generate specific report" (accept custom params, truly generate)
|
|
||||||
config.add_route('generate_specific_report', '/reports/generate/{type_key}')
|
|
||||||
config.add_view(cls, attr='generate', route_name='generate_specific_report',
|
config.add_view(cls, attr='generate', route_name='generate_specific_report',
|
||||||
permission='report_output.generate',
|
permission='{}.create'.format(permission_prefix))
|
||||||
renderer='/reports/generate.mako')
|
|
||||||
|
|
||||||
|
|
||||||
@colander.deferred
|
@colander.deferred
|
||||||
|
@ -680,18 +665,13 @@ def add_routes(config):
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
add_routes(config)
|
|
||||||
|
|
||||||
|
# TODO: not in love with this pattern, but works for now
|
||||||
|
add_routes(config)
|
||||||
config.add_view(OrderingWorksheet, route_name='reports.ordering',
|
config.add_view(OrderingWorksheet, route_name='reports.ordering',
|
||||||
renderer='/reports/ordering.mako')
|
renderer='/reports/ordering.mako')
|
||||||
|
|
||||||
config.add_view(InventoryWorksheet, route_name='reports.inventory',
|
config.add_view(InventoryWorksheet, route_name='reports.inventory',
|
||||||
renderer='/reports/inventory.mako')
|
renderer='/reports/inventory.mako')
|
||||||
|
|
||||||
# fix permission group
|
|
||||||
config.add_tailbone_permission_group('report_output', "Generated Reports")
|
|
||||||
|
|
||||||
# note that GenerateReport must come first, per route matching
|
|
||||||
GenerateReport.defaults(config)
|
|
||||||
ReportOutputView.defaults(config)
|
ReportOutputView.defaults(config)
|
||||||
ProblemReportView.defaults(config)
|
ProblemReportView.defaults(config)
|
||||||
|
|
Loading…
Reference in a new issue