Add support for "list" type of app settings (w/ textarea)

This commit is contained in:
Lance Edgar 2020-09-25 23:23:01 -05:00
parent 18b9f43eaa
commit 37a05155e5
2 changed files with 25 additions and 1 deletions

View file

@ -108,6 +108,12 @@
v-model="setting.value" v-model="setting.value"
value="true" /> value="true" />
<b-input v-else-if="setting.data_type == 'list'"
type="textarea"
:name="setting.field_name"
v-model="setting.value">
</b-input>
<b-select v-else-if="setting.choices" <b-select v-else-if="setting.choices"
:name="setting.field_name" :name="setting.field_name"
:id="setting.field_name" :id="setting.field_name"

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -226,6 +226,9 @@ class AppSettingsView(View):
def get_setting_value(self, setting): def get_setting_value(self, setting):
if setting.data_type is bool: if setting.data_type is bool:
return self.rattail_config.getbool(setting.namespace, setting.name) return self.rattail_config.getbool(setting.namespace, setting.name)
if setting.data_type is list:
return '\n'.join(
self.rattail_config.getlist(setting.namespace, setting.name))
return self.rattail_config.get(setting.namespace, setting.name) return self.rattail_config.get(setting.namespace, setting.name)
def save_setting_value(self, setting, value): def save_setting_value(self, setting, value):
@ -234,10 +237,25 @@ class AppSettingsView(View):
legacy_name = '{}.{}'.format(setting.namespace, setting.name) legacy_name = '{}.{}'.format(setting.namespace, setting.name)
if setting.data_type is bool: if setting.data_type is bool:
value = 'true' if value else 'false' value = 'true' if value else 'false'
elif setting.data_type is list:
entries = [self.clean_list_entry(entry)
for entry in value.split('\n')]
value = ', '.join(entries)
else: else:
value = six.text_type(value) value = six.text_type(value)
api.save_setting(Session(), legacy_name, value) api.save_setting(Session(), legacy_name, value)
def clean_list_entry(self, value):
value = value.strip()
if '"' in value and "'" in value:
raise NotImplementedError("don't know how to handle escaping 2 "
"different types of quotes!")
if '"' in value:
return "'{}'".format(value)
if "'" in value:
return '"{}"'.format(value)
return value
@classmethod @classmethod
def defaults(cls, config): def defaults(cls, config):
config.add_route('appsettings', '/settings/app/') config.add_route('appsettings', '/settings/app/')