Add "multi-engine" support for Trainwreck transaction views

This commit is contained in:
Lance Edgar 2019-07-25 15:40:38 -05:00
parent b07365b487
commit e756ae3c8f
4 changed files with 40 additions and 5 deletions

View file

@ -130,6 +130,8 @@ class MasterView(View):
# other things also, to get a DB picker in the header for all views
supports_multiple_engines = False
engine_type_key = 'rattail'
SessionDefault = None
SessionExtras = {}
row_attrs = {}
cell_attrs = {}
@ -172,9 +174,16 @@ class MasterView(View):
@property
def Session(self):
"""
SQLAlchemy scoped session to use when querying the database. Defaults
to ``tailbone.db.Session``.
Which session we return may depend on user's "current" engine.
"""
if self.supports_multiple_engines:
dbkey = self.get_current_engine_dbkey()
if dbkey != 'default' and dbkey in self.SessionExtras:
return self.SessionExtras[dbkey]
if self.SessionDefault:
return self.SessionDefault
from tailbone.db import Session
return Session