fix: avoid deprecated config methods for app/node title

This commit is contained in:
Lance Edgar 2024-06-09 23:07:52 -05:00
parent 7c3d5b46f3
commit b8ace1eb98
7 changed files with 23 additions and 15 deletions

View file

@ -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!"}

View file

@ -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

View file

@ -1,6 +1,6 @@
## -*- coding: utf-8; -*-
<%def name="app_title()">${request.rattail_config.node_title(default="Rattail")}</%def>
<%def name="app_title()">${rattail_app.get_node_title()}</%def>
<%def name="global_title()">${"[STAGE] " if not request.rattail_config.production() else ''}${self.app_title()}</%def>

View file

@ -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),
}

View file

@ -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)

View file

@ -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')

View file

@ -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: