Add basic master view for Report Output data model

This commit is contained in:
Lance Edgar 2017-03-22 14:27:59 -05:00
parent e34bd947bc
commit 6adb99003d
3 changed files with 60 additions and 11 deletions

View file

@ -65,7 +65,7 @@ class FileFieldRenderer(BaseFileFieldRenderer):
if size: if size:
return size return size
batch = self.field.parent.model 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): if os.path.isfile(path):
return os.stat(path)[stat.ST_SIZE] return os.stat(path)[stat.ST_SIZE]
return 0 return 0

View file

@ -56,6 +56,7 @@ class MasterView(View):
deletable = True deletable = True
bulk_deletable = False bulk_deletable = False
mergeable = False mergeable = False
downloadable = False
supports_mobile = 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), config.add_view(cls, attr='mobile_view', route_name='mobile.{}.view'.format(route_prefix),
permission='{}.view'.format(permission_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 # edit
if cls.editable: if cls.editable:
config.add_route('{0}.edit'.format(route_prefix), '{0}/{{{1}}}/edit'.format(url_prefix, model_key)) config.add_route('{0}.edit'.format(route_prefix), '{0}/{{{1}}}/edit'.format(url_prefix, model_key))

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8; -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2015 Lance Edgar # Copyright © 2010-2017 Lance Edgar
# #
# This file is part of Rattail. # 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 import re
from .core import View
from mako.template import Template
from pyramid.response import Response
from ..db import Session
import rattail import rattail
from rattail import enum 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
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})$') plu_upc_pattern = re.compile(r'^000000000(\d{5})$')
weighted_upc_pattern = re.compile(r'^002(\d{5})00000\d$') weighted_upc_pattern = re.compile(r'^002(\d{5})00000\d$')
def get_upc(product): def get_upc(product):
""" """
UPC formatter. Strips PLUs to bare number, and adds "minus check digit" UPC formatter. Strips PLUs to bare number, and adds "minus check digit"
@ -192,6 +195,41 @@ class InventoryWorksheet(View):
return template.render(**data) 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): def add_routes(config):
config.add_route('reports.ordering', '/reports/ordering') config.add_route('reports.ordering', '/reports/ordering')
config.add_route('reports.inventory', '/reports/inventory') config.add_route('reports.inventory', '/reports/inventory')
@ -205,3 +243,5 @@ def includeme(config):
config.add_view(InventoryWorksheet, route_name='reports.inventory', config.add_view(InventoryWorksheet, route_name='reports.inventory',
renderer='/reports/inventory.mako') renderer='/reports/inventory.mako')
ReportOutputView.defaults(config)