Don't save any App Settings for which value would not change

that lets us avoid writing "redundant" values to the database, whereas in fact
the underlying value may be coming from config file
This commit is contained in:
Lance Edgar 2018-07-18 13:50:32 -05:00
parent 117e52df23
commit c2968fbe52
2 changed files with 8 additions and 6 deletions

View file

@ -1,7 +1,7 @@
## -*- coding: utf-8; -*- ## -*- coding: utf-8; -*-
<%inherit file="/base.mako" /> <%inherit file="/base.mako" />
<%def name="title()">${self.app_title()} App Settings</%def> <%def name="title()">App Settings</%def>
<%def name="content_title()"></%def> <%def name="content_title()"></%def>

View file

@ -180,11 +180,13 @@ class AppSettingsView(View):
return self.rattail_config.get(setting.namespace, setting.name, default='') return self.rattail_config.get(setting.namespace, setting.name, default='')
def save_setting_value(self, setting, value): def save_setting_value(self, setting, value):
legacy_name = '{}.{}'.format(setting.namespace, setting.name) existing = self.get_setting_value(setting)
if setting.data_type is bool: if existing != value:
api.save_setting(Session(), legacy_name, 'true' if value else 'false') legacy_name = '{}.{}'.format(setting.namespace, setting.name)
else: if setting.data_type is bool:
api.save_setting(Session(), legacy_name, six.text_type(value)) api.save_setting(Session(), legacy_name, 'true' if value else 'false')
else:
api.save_setting(Session(), legacy_name, six.text_type(value))
@classmethod @classmethod
def defaults(cls, config): def defaults(cls, config):