fix: always define app attr for ViewSupplement

This commit is contained in:
Lance Edgar 2024-11-12 18:26:36 -06:00
parent 3f27f626df
commit 772b6610cb

View file

@ -903,7 +903,7 @@ class MasterView(View):
def valid_employee_uuid(self, node, value): def valid_employee_uuid(self, node, value):
if value: if value:
model = self.model model = self.app.model
employee = self.Session.get(model.Employee, value) employee = self.Session.get(model.Employee, value)
if not employee: if not employee:
node.raise_invalid("Employee not found") node.raise_invalid("Employee not found")
@ -939,7 +939,7 @@ class MasterView(View):
def valid_vendor_uuid(self, node, value): def valid_vendor_uuid(self, node, value):
if value: if value:
model = self.model model = self.app.model
vendor = self.Session.get(model.Vendor, value) vendor = self.Session.get(model.Vendor, value)
if not vendor: if not vendor:
node.raise_invalid("Vendor not found") node.raise_invalid("Vendor not found")
@ -1382,7 +1382,7 @@ class MasterView(View):
return classes return classes
def make_revisions_grid(self, obj, empty_data=False): def make_revisions_grid(self, obj, empty_data=False):
model = self.model model = self.app.model
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
row_url = lambda txn, i: self.request.route_url(f'{route_prefix}.version', row_url = lambda txn, i: self.request.route_url(f'{route_prefix}.version',
uuid=obj.uuid, uuid=obj.uuid,
@ -2153,7 +2153,7 @@ class MasterView(View):
Thread target for executing an object. Thread target for executing an object.
""" """
app = self.get_rattail_app() app = self.get_rattail_app()
model = self.model model = self.app.model
session = app.make_session() session = app.make_session()
obj = self.get_instance_for_key(key, session) obj = self.get_instance_for_key(key, session)
user = session.get(model.User, user_uuid) user = session.get(model.User, user_uuid)
@ -2594,7 +2594,7 @@ class MasterView(View):
""" """
# nb. self.Session may differ, so use tailbone.db.Session # nb. self.Session may differ, so use tailbone.db.Session
session = Session() session = Session()
model = self.model model = self.app.model
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
info = session.query(model.TailbonePageHelp)\ info = session.query(model.TailbonePageHelp)\
@ -2617,7 +2617,7 @@ class MasterView(View):
""" """
# nb. self.Session may differ, so use tailbone.db.Session # nb. self.Session may differ, so use tailbone.db.Session
session = Session() session = Session()
model = self.model model = self.app.model
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
info = session.query(model.TailbonePageHelp)\ info = session.query(model.TailbonePageHelp)\
@ -2639,7 +2639,7 @@ class MasterView(View):
# nb. self.Session may differ, so use tailbone.db.Session # nb. self.Session may differ, so use tailbone.db.Session
session = Session() session = Session()
model = self.model model = self.app.model
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
schema = colander.Schema() schema = colander.Schema()
@ -2673,7 +2673,7 @@ class MasterView(View):
# nb. self.Session may differ, so use tailbone.db.Session # nb. self.Session may differ, so use tailbone.db.Session
session = Session() session = Session()
model = self.model model = self.app.model
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
schema = colander.Schema() schema = colander.Schema()
@ -5541,7 +5541,7 @@ class MasterView(View):
input_file_templates=True, input_file_templates=True,
output_file_templates=True): output_file_templates=True):
app = self.get_rattail_app() app = self.get_rattail_app()
model = self.model model = self.app.model
names = [] names = []
if simple_settings is None: if simple_settings is None:
@ -6100,7 +6100,7 @@ class MasterView(View):
renderer='json') renderer='json')
class ViewSupplement(object): class ViewSupplement:
""" """
Base class for view "supplements" - which are sort of like plugins Base class for view "supplements" - which are sort of like plugins
which can "supplement" certain aspects of the view. which can "supplement" certain aspects of the view.
@ -6127,6 +6127,7 @@ class ViewSupplement(object):
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self.request = master.request self.request = master.request
self.app = master.app
self.model = master.model self.model = master.model
self.rattail_config = master.rattail_config self.rattail_config = master.rattail_config
self.Session = master.Session self.Session = master.Session
@ -6160,7 +6161,7 @@ class ViewSupplement(object):
This is accomplished by subjecting the current base query to a This is accomplished by subjecting the current base query to a
join, e.g. something like:: join, e.g. something like::
model = self.model model = self.app.model
query = query.outerjoin(model.MyExtension) query = query.outerjoin(model.MyExtension)
return query return query
""" """