From 128657810bed9aab0de8e5a934029aa54f17b8a7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 5 Mar 2022 09:10:05 -0600 Subject: [PATCH] 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.. --- tailbone/views/poser/master.py | 73 +++++++++++++++++++++++++++++++++ tailbone/views/poser/reports.py | 42 ++++--------------- tailbone/views/reports.py | 2 +- 3 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 tailbone/views/poser/master.py diff --git a/tailbone/views/poser/master.py b/tailbone/views/poser/master.py new file mode 100644 index 00000000..1f04fe61 --- /dev/null +++ b/tailbone/views/poser/master.py @@ -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 . +# +################################################################################ +""" +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") diff --git a/tailbone/views/poser/reports.py b/tailbone/views/poser/reports.py index 972ee66f..80876233 100644 --- a/tailbone/views/poser/reports.py +++ b/tailbone/views/poser/reports.py @@ -34,22 +34,20 @@ from rattail.util import simple_error import colander 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 """ - normalized_model_name = 'poserreport' + normalized_model_name = 'poser_report' model_title = "Poser Report" model_key = 'report_key' - route_prefix = 'poser.reports' + route_prefix = 'poser_reports' url_prefix = '/poser/reports' - filterable = False - pageable = False editable = False # TODO: should allow this somehow? downloadable = True @@ -93,34 +91,8 @@ class PoserReportView(MasterView): 'created_by', ] - def __init__(self, request): - super(PoserReportView, self).__init__(request) - 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 get_poser_data(self, session=None): + return self.poser_handler.get_all_reports() def configure_grid(self, g): super(PoserReportView, self).configure_grid(g) diff --git a/tailbone/views/reports.py b/tailbone/views/reports.py index 0319b725..74cba68d 100644 --- a/tailbone/views/reports.py +++ b/tailbone/views/reports.py @@ -272,7 +272,7 @@ class ReportOutputView(ExportMasterView): poser_key = type_key[6:] report = poser_handler.normalize_report(poser_key) 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) return tags.link_to(type_key, url)