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

@ -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