Add PoserMasterView, rename route for poser_reports

must use e.g. `poser_reports` and `poser_views` for the "meta" stuff,
i.e. maintenance of actual poser things, b/c it will be possible to
define poser views, and those routes should be `poser.*` probably..
This commit is contained in:
Lance Edgar 2022-03-05 09:10:05 -06:00
parent f5d24133f7
commit 128657810b
3 changed files with 81 additions and 36 deletions

View file

@ -0,0 +1,73 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Poser Views for Views...
"""
from __future__ import unicode_literals, absolute_import
from rattail.util import simple_error
from webhelpers2.html import HTML, tags
from tailbone.views import MasterView
class PoserMasterView(MasterView):
"""
Master view base class for Poser
"""
model_key = 'key'
filterable = False
pageable = False
def __init__(self, request):
super(PoserMasterView, self).__init__(request)
app = self.get_rattail_app()
self.poser_handler = app.get_poser_handler()
# nb. pre-load all data b/c all views potentially need access
self.data = self.get_data()
def get_data(self, session=None):
if hasattr(self, 'data'):
return self.data
try:
return self.get_poser_data(session)
except Exception as error:
self.request.session.flash(simple_error(error), 'error')
if not self.request.is_root:
self.request.session.flash("You must become root in order "
"to do Poser Setup.", 'error')
else:
link = tags.link_to("Poser Setup",
self.request.route_url('poser_setup'))
msg = HTML.literal("Please see the {} page.".format(link))
self.request.session.flash(msg, 'error')
return []
def get_poser_data(self, session=None):
raise NotImplementedError("TODO: you must implement this in subclass")

View file

@ -34,22 +34,20 @@ from rattail.util import simple_error
import colander import colander
from deform import widget as dfwidget from deform import widget as dfwidget
from webhelpers2.html import HTML, tags from webhelpers2.html import HTML
from tailbone.views import MasterView from .master import PoserMasterView
class PoserReportView(MasterView): class PoserReportView(PoserMasterView):
""" """
Master view for Poser reports Master view for Poser reports
""" """
normalized_model_name = 'poserreport' normalized_model_name = 'poser_report'
model_title = "Poser Report" model_title = "Poser Report"
model_key = 'report_key' model_key = 'report_key'
route_prefix = 'poser.reports' route_prefix = 'poser_reports'
url_prefix = '/poser/reports' url_prefix = '/poser/reports'
filterable = False
pageable = False
editable = False # TODO: should allow this somehow? editable = False # TODO: should allow this somehow?
downloadable = True downloadable = True
@ -93,34 +91,8 @@ class PoserReportView(MasterView):
'created_by', 'created_by',
] ]
def __init__(self, request): def get_poser_data(self, session=None):
super(PoserReportView, self).__init__(request) return self.poser_handler.get_all_reports()
app = self.get_rattail_app()
self.poser_handler = app.get_poser_handler()
# nb. pre-load all reports b/c all views potentially need
# access to the data set
self.data = self.get_data()
def get_data(self, session=None):
if hasattr(self, 'data'):
return self.data
try:
return self.poser_handler.get_all_reports()
except Exception as error:
self.request.session.flash(simple_error(error), 'error')
if not self.request.is_root:
self.request.session.flash("You must become root in order "
"to do Poser Setup.", 'error')
else:
link = tags.link_to("Poser Setup",
self.request.route_url('poser_setup'))
msg = HTML.literal("Please see the {} page.".format(link))
self.request.session.flash(msg, 'error')
return []
def configure_grid(self, g): def configure_grid(self, g):
super(PoserReportView, self).configure_grid(g) super(PoserReportView, self).configure_grid(g)

View file

@ -272,7 +272,7 @@ class ReportOutputView(ExportMasterView):
poser_key = type_key[6:] poser_key = type_key[6:]
report = poser_handler.normalize_report(poser_key) report = poser_handler.normalize_report(poser_key)
if not report.get('error'): if not report.get('error'):
url = self.request.route_url('poser.reports.view', url = self.request.route_url('poser_reports.view',
report_key=poser_key) report_key=poser_key)
return tags.link_to(type_key, url) return tags.link_to(type_key, url)