Make sure "configure" pages use AppHandler to save/delete settings

so that beaker config cache is invalidated, if in use
This commit is contained in:
Lance Edgar 2022-08-07 18:23:15 -05:00
parent 6352a6dc9a
commit fe4c3d4942
5 changed files with 45 additions and 33 deletions

View file

@ -436,15 +436,18 @@ class VendorCatalogView(FileBatchMasterView):
def configure_remove_settings(self):
super(VendorCatalogView, self).configure_remove_settings()
model = self.model
app = self.get_rattail_app()
names = [
'rattail.vendors.supported_catalog_parsers',
'tailbone.batch.vendorcatalog.supported_parsers', # deprecated
]
Session().query(model.Setting)\
.filter(model.Setting.name.in_(names))\
.delete(synchronize_session=False)
# nb. using thread-local session here; we do not use
# self.Session b/c it may not point to Rattail
session = Session()
for name in names:
app.delete_setting(session, name)
# TODO: deprecate / remove this

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar
# Copyright © 2010-2022 Lance Edgar
#
# This file is part of Rattail.
#
@ -576,13 +576,19 @@ cd {prefix}
return settings
def configure_remove_settings(self):
app = self.get_rattail_app()
model = self.model
self.Session.query(model.Setting)\
session = self.Session()
to_delete = session.query(model.Setting)\
.filter(sa.or_(
model.Setting.name.like('rattail.importing.%.handler'),
model.Setting.name.like('rattail.importing.%.cmd'),
model.Setting.name.like('rattail.importing.%.runas')))\
.delete(synchronize_session=False)
.all()
for setting in to_delete:
app.delete_setting(session, setting)
@classmethod
def defaults(cls, config):

View file

@ -4482,6 +4482,7 @@ class MasterView(View):
def configure_remove_settings(self, simple_settings=None,
input_file_templates=True):
app = self.get_rattail_app()
model = self.model
names = []
@ -4500,20 +4501,21 @@ class MasterView(View):
])
if names:
# nb. we do not use self.Session b/c that may not point to
# the Rattail DB for the subclass
Session().query(model.Setting)\
.filter(model.Setting.name.in_(names))\
.delete(synchronize_session=False)
# nb. using thread-local session here; we do not use
# self.Session b/c it may not point to Rattail
session = Session()
for name in names:
app.delete_setting(session, name)
def configure_save_settings(self, settings):
model = self.model
# nb. we do not use self.Session b/c that may not point to the
# Rattail DB for the subclass
app = self.get_rattail_app()
# nb. using thread-local session here; we do not use
# self.Session b/c it may not point to Rattail
session = Session()
for setting in settings:
session.add(model.Setting(name=setting['name'],
value=setting['value']))
app.save_setting(session, setting['name'], setting['value'],
force_create=True)
##############################
# Pyramid View Config

View file

@ -417,16 +417,18 @@ class TransactionView(MasterView):
def configure_remove_settings(self):
super(TransactionView, self).configure_remove_settings()
app = self.get_rattail_app()
model = self.model
names = [
'trainwreck.db.hide',
'tailbone.engines.trainwreck.hidden', # deprecated
]
# nb. we do not use self.Session b/c that points to trainwreck
Session.query(model.Setting)\
.filter(model.Setting.name.in_(names))\
.delete(synchronize_session=False)
# nb. using thread-local session here; we do not use
# self.Session b/c it may not point to Rattail
session = Session()
for name in names:
app.delete_setting(session, name)
@classmethod
def defaults(cls, config):

View file

@ -202,8 +202,7 @@ class VendorView(MasterView):
def configure_remove_settings(self, **kwargs):
super(VendorView, self).configure_remove_settings(**kwargs)
model = self.model
app = self.get_rattail_app()
names = []
supported_vendor_settings = self.configure_get_supported_vendor_settings()
@ -211,11 +210,11 @@ class VendorView(MasterView):
names.append('rattail.vendor.{}'.format(setting['key']))
if names:
# nb. we do not use self.Session b/c that may not point to
# the Rattail DB for the subclass
Session().query(model.Setting)\
.filter(model.Setting.name.in_(names))\
.delete(synchronize_session=False)
# nb. using thread-local session here; we do not use
# self.Session b/c it may not point to Rattail
session = Session()
for name in names:
app.delete_setting(session, name)
def configure_get_supported_vendor_settings(self):
app = self.get_rattail_app()