Add support for "list" type of app settings (w/ textarea)
This commit is contained in:
parent
18b9f43eaa
commit
37a05155e5
|
@ -108,6 +108,12 @@
|
|||
v-model="setting.value"
|
||||
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"
|
||||
:name="setting.field_name"
|
||||
:id="setting.field_name"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -226,6 +226,9 @@ class AppSettingsView(View):
|
|||
def get_setting_value(self, setting):
|
||||
if setting.data_type is bool:
|
||||
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)
|
||||
|
||||
def save_setting_value(self, setting, value):
|
||||
|
@ -234,10 +237,25 @@ class AppSettingsView(View):
|
|||
legacy_name = '{}.{}'.format(setting.namespace, setting.name)
|
||||
if setting.data_type is bool:
|
||||
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:
|
||||
value = six.text_type(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
|
||||
def defaults(cls, config):
|
||||
config.add_route('appsettings', '/settings/app/')
|
||||
|
|
Loading…
Reference in a new issue