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

View file

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

View file

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

View file

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

View file

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