diff --git a/tailbone/api/common.py b/tailbone/api/common.py index 30dfeab1..1dcaff08 100644 --- a/tailbone/api/common.py +++ b/tailbone/api/common.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2023 Lance Edgar +# Copyright © 2010-2024 Lance Edgar # # This file is part of Rattail. # @@ -27,8 +27,6 @@ Tailbone Web API - "Common" Views from collections import OrderedDict import rattail -from rattail.db import model -from rattail.mail import send_email from cornice import Service from cornice.service import get_services @@ -66,7 +64,8 @@ class CommonView(APIView): } def get_project_title(self): - return self.rattail_config.app_title(default="Tailbone") + app = self.get_rattail_app() + return app.get_title() def get_project_version(self): import tailbone @@ -87,6 +86,8 @@ class CommonView(APIView): """ View to handle user feedback form submits. """ + app = self.get_rattail_app() + model = self.model # TODO: this logic was copied from tailbone.views.common and is largely # identical; perhaps should merge somehow? schema = Feedback().bind(session=Session()) @@ -106,7 +107,7 @@ class CommonView(APIView): data['client_ip'] = self.request.client_addr email_key = data['email_key'] or self.feedback_email_key - send_email(self.rattail_config, email_key, data=data) + app.send_email(email_key, data=data) return {'ok': True} return {'error': "Form did not validate!"} diff --git a/tailbone/subscribers.py b/tailbone/subscribers.py index 42d3cab7..bc851629 100644 --- a/tailbone/subscribers.py +++ b/tailbone/subscribers.py @@ -165,10 +165,11 @@ def before_render(event): request = event.get('request') or threadlocal.get_current_request() rattail_config = request.rattail_config + app = rattail_config.get_app() renderer_globals = event - renderer_globals['rattail_app'] = request.rattail_config.get_app() - renderer_globals['app_title'] = request.rattail_config.app_title() + renderer_globals['rattail_app'] = app + renderer_globals['app_title'] = app.get_title() renderer_globals['h'] = helpers renderer_globals['url'] = request.route_url renderer_globals['rattail'] = rattail diff --git a/tailbone/templates/base_meta.mako b/tailbone/templates/base_meta.mako index 07b13e61..00cfdfe9 100644 --- a/tailbone/templates/base_meta.mako +++ b/tailbone/templates/base_meta.mako @@ -1,6 +1,6 @@ ## -*- coding: utf-8; -*- -<%def name="app_title()">${request.rattail_config.node_title(default="Rattail")} +<%def name="app_title()">${rattail_app.get_node_title()} <%def name="global_title()">${"[STAGE] " if not request.rattail_config.production() else ''}${self.app_title()} diff --git a/tailbone/views/auth.py b/tailbone/views/auth.py index 0f0d1687..7ecdc6cd 100644 --- a/tailbone/views/auth.py +++ b/tailbone/views/auth.py @@ -92,6 +92,7 @@ class AuthenticationView(View): """ The login view, responsible for displaying and handling the login form. """ + app = self.get_rattail_app() referrer = self.request.get_referrer(default=self.request.route_url('home')) # redirect if already logged in @@ -133,7 +134,7 @@ class AuthenticationView(View): 'form': form, 'referrer': referrer, 'image_url': image_url, - 'index_title': self.rattail_config.node_title(), + 'index_title': app.get_node_title(), 'help_url': global_help_url(self.rattail_config), } diff --git a/tailbone/views/common.py b/tailbone/views/common.py index 266561fd..25eb7dee 100644 --- a/tailbone/views/common.py +++ b/tailbone/views/common.py @@ -50,6 +50,7 @@ class CommonView(View): """ Home page view. """ + app = self.get_rattail_app() if not self.request.user: if self.rattail_config.getbool('tailbone', 'login_is_home', default=True): raise self.redirect(self.request.route_url('login')) @@ -60,7 +61,7 @@ class CommonView(View): context = { 'image_url': image_url, - 'index_title': self.rattail_config.node_title(), + 'index_title': app.get_node_title(), 'help_url': global_help_url(self.rattail_config), } @@ -99,7 +100,8 @@ class CommonView(View): return response def get_project_title(self): - return self.rattail_config.app_title() + app = self.get_rattail_app() + return app.get_title() def get_project_version(self): @@ -121,11 +123,12 @@ class CommonView(View): """ Generic view to show "about project" info page. """ + app = self.get_rattail_app() return { 'project_title': self.get_project_title(), 'project_version': self.get_project_version(), 'packages': self.get_packages(), - 'index_title': self.rattail_config.node_title(), + 'index_title': app.get_node_title(), } def get_packages(self): @@ -209,7 +212,7 @@ class CommonView(View): raise self.forbidden() app = self.get_rattail_app() - app_title = self.rattail_config.app_title() + app_title = app.get_title() poser_handler = app.get_poser_handler() poser_dir = poser_handler.get_default_poser_dir() poser_dir_exists = os.path.isdir(poser_dir) diff --git a/tailbone/views/settings.py b/tailbone/views/settings.py index cce5e53d..8d389530 100644 --- a/tailbone/views/settings.py +++ b/tailbone/views/settings.py @@ -67,8 +67,9 @@ class AppInfoView(MasterView): ] def get_index_title(self): + app = self.get_rattail_app() return "{} for {}".format(self.get_model_title_plural(), - self.rattail_config.app_title()) + app.get_title()) def get_data(self, session=None): pip = os.path.join(sys.prefix, 'bin', 'pip') diff --git a/tailbone/views/upgrades.py b/tailbone/views/upgrades.py index a281062e..3276b64d 100644 --- a/tailbone/views/upgrades.py +++ b/tailbone/views/upgrades.py @@ -147,10 +147,11 @@ class UpgradeView(MasterView): def template_kwargs_view(self, **kwargs): kwargs = super().template_kwargs_view(**kwargs) + app = self.get_rattail_app() model = self.model upgrade = kwargs['instance'] - kwargs['system_title'] = self.rattail_config.app_title() + kwargs['system_title'] = app.get_title() if upgrade.system: system = self.upgrade_handler.get_system(upgrade.system) if system: