diff --git a/tailbone/forms/renderers/batch.py b/tailbone/forms/renderers/batch.py index be63d9e6..2b6e1168 100644 --- a/tailbone/forms/renderers/batch.py +++ b/tailbone/forms/renderers/batch.py @@ -65,7 +65,7 @@ class FileFieldRenderer(BaseFileFieldRenderer): if size: return size batch = self.field.parent.model - path = os.path.join(self.view.handler.datadir(batch), self.field.value) + path = batch.filepath(self.request.rattail_config, filename=self.field.value) if os.path.isfile(path): return os.stat(path)[stat.ST_SIZE] return 0 diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 89037890..97fbe21c 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -56,6 +56,7 @@ class MasterView(View): deletable = True bulk_deletable = False mergeable = False + downloadable = False supports_mobile = False @@ -1456,6 +1457,14 @@ class MasterView(View): config.add_view(cls, attr='mobile_view', route_name='mobile.{}.view'.format(route_prefix), permission='{}.view'.format(permission_prefix)) + # download + if cls.downloadable: + config.add_route('{}.download'.format(route_prefix), '{}/{{{}}}/download'.format(url_prefix, model_key)) + config.add_view(cls, attr='download', route_name='{}.download'.format(route_prefix), + permission='{}.download'.format(permission_prefix)) + config.add_tailbone_permission(permission_prefix, '{}.download'.format(permission_prefix), + "Download associated data for {}".format(model_title)) + # edit if cls.editable: config.add_route('{0}.edit'.format(route_prefix), '{0}/{{{1}}}/edit'.format(url_prefix, model_key)) diff --git a/tailbone/views/reports.py b/tailbone/views/reports.py index 6a8df2a2..82b7a4f5 100644 --- a/tailbone/views/reports.py +++ b/tailbone/views/reports.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -21,29 +21,32 @@ # ################################################################################ """ -Report Views +Reporting views """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import import re -from .core import View -from mako.template import Template -from pyramid.response import Response - -from ..db import Session - import rattail from rattail import enum from rattail.db import model from rattail.files import resource_path from rattail.time import localtime +from mako.template import Template +from pyramid.response import Response + +from tailbone import forms +from tailbone.db import Session +from tailbone.views import View +from tailbone.views.exports import ExportMasterView + plu_upc_pattern = re.compile(r'^000000000(\d{5})$') weighted_upc_pattern = re.compile(r'^002(\d{5})00000\d$') + def get_upc(product): """ UPC formatter. Strips PLUs to bare number, and adds "minus check digit" @@ -192,6 +195,41 @@ class InventoryWorksheet(View): return template.render(**data) +class ReportOutputView(ExportMasterView): + model_class = model.ReportOutput + route_prefix = 'report_output' + url_prefix = '/reports/generated' + + def configure_grid(self, g): + g.configure( + include=[ + g.id, + g.report_name, + g.filename, + g.created, + g.created_by, + ], + readonly=True) + + def _preconfigure_fieldset(self, fs): + super(ReportOutputView, self)._preconfigure_fieldset(fs) + if self.viewing: + report = self.get_instance() + 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): + fs.configure(include=[ + fs.id, + fs.report_name, + fs.filename, + fs.created, + fs.created_by, + ]) + + def add_routes(config): config.add_route('reports.ordering', '/reports/ordering') config.add_route('reports.inventory', '/reports/inventory') @@ -205,3 +243,5 @@ def includeme(config): config.add_view(InventoryWorksheet, route_name='reports.inventory', renderer='/reports/inventory.mako') + + ReportOutputView.defaults(config)