Make common web view a bit more common

i.e. avoid the need to subclass it in derived projects
This commit is contained in:
Lance Edgar 2022-03-04 17:44:34 -06:00
parent a28a801a62
commit f5d24133f7

View file

@ -28,17 +28,15 @@ from __future__ import unicode_literals, absolute_import
import six
import rattail
from rattail.db import model
from rattail.batch import consume_batch_id
from rattail.mail import send_email
from rattail.util import OrderedDict, simple_error
from rattail.util import OrderedDict, simple_error, import_module_path
from rattail.files import resource_path
from pyramid import httpexceptions
from pyramid.response import Response
import tailbone
from tailbone import forms
from tailbone.forms.common import Feedback
from tailbone.db import Session
@ -51,8 +49,6 @@ class CommonView(View):
"""
Base class for common views; override as needed.
"""
project_title = "Tailbone"
project_version = tailbone.__version__
robots_txt_path = resource_path('tailbone.static:robots.txt')
def home(self, **kwargs):
@ -96,11 +92,24 @@ class CommonView(View):
response.content_type = b'text/plain'
return response
def get_project_title(self):
return self.rattail_config.app_title()
def get_project_version(self):
# TODO: deprecate this
if hasattr(self, 'project_version'):
return self.project_version
pkg = self.rattail_config.app_package()
mod = import_module_path(pkg)
return mod.__version__
def exception(self):
"""
Generic exception view
"""
return {'project_title': self.project_title}
return {'project_title': self.get_project_title()}
def about(self):
"""
@ -108,8 +117,8 @@ class CommonView(View):
"""
use_buefy = self.get_use_buefy()
context = {
'project_title': self.project_title,
'project_version': self.project_version,
'project_title': self.get_project_title(),
'project_version': self.get_project_version(),
'packages': self.get_packages(),
'use_buefy': use_buefy,
}
@ -122,6 +131,7 @@ class CommonView(View):
Should return the full set of packages which should be displayed on the
'about' page.
"""
import rattail, tailbone
return OrderedDict([
('rattail', rattail.__version__),
('Tailbone', tailbone.__version__),