Add initial support for editing user preferences
by default this exposes just one setting which has only one possible value, so not very useful. but can override as needed
This commit is contained in:
parent
6093be43c9
commit
962d31c4c2
6 changed files with 239 additions and 24 deletions
|
@ -4290,6 +4290,7 @@ class MasterView(View):
|
|||
'type': bool,
|
||||
'value': config.getbool('rattail.batch',
|
||||
'purchase.allow_cases'),
|
||||
'save_if_empty': False,
|
||||
}
|
||||
|
||||
Note that some of the above is optional, in particular it
|
||||
|
@ -4316,9 +4317,11 @@ class MasterView(View):
|
|||
return '{}.{}'.format(simple['section'],
|
||||
simple['option'])
|
||||
|
||||
def configure_get_context(self):
|
||||
def configure_get_context(self, simple_settings=None,
|
||||
input_file_templates=True):
|
||||
context = {}
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings is None:
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings:
|
||||
|
||||
config = self.rattail_config
|
||||
|
@ -4342,7 +4345,7 @@ class MasterView(View):
|
|||
context['simple_settings'] = settings
|
||||
|
||||
# add settings for downloadable input file templates, if any
|
||||
if self.has_input_file_templates:
|
||||
if input_file_templates and self.has_input_file_templates:
|
||||
settings = {}
|
||||
file_options = {}
|
||||
file_option_dirs = {}
|
||||
|
@ -4359,11 +4362,13 @@ class MasterView(View):
|
|||
|
||||
return context
|
||||
|
||||
def configure_gather_settings(self, data):
|
||||
def configure_gather_settings(self, data, simple_settings=None,
|
||||
input_file_templates=True):
|
||||
settings = []
|
||||
|
||||
# maybe collect "simple" settings
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings is None:
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings:
|
||||
|
||||
for simple in simple_settings:
|
||||
|
@ -4377,11 +4382,14 @@ class MasterView(View):
|
|||
else:
|
||||
value = six.text_type(value)
|
||||
|
||||
settings.append({'name': name,
|
||||
'value': value})
|
||||
# only want to save this setting if we received a
|
||||
# value, or if empty values are okay to save
|
||||
if value or simple.get('save_if_empty'):
|
||||
settings.append({'name': name,
|
||||
'value': value})
|
||||
|
||||
# maybe also collect input file template settings
|
||||
if self.has_input_file_templates:
|
||||
if input_file_templates and self.has_input_file_templates:
|
||||
for template in self.normalize_input_file_templates():
|
||||
|
||||
# mode
|
||||
|
@ -4401,16 +4409,18 @@ class MasterView(View):
|
|||
|
||||
return settings
|
||||
|
||||
def configure_remove_settings(self):
|
||||
def configure_remove_settings(self, simple_settings=None,
|
||||
input_file_templates=True):
|
||||
model = self.model
|
||||
names = []
|
||||
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings is None:
|
||||
simple_settings = self.configure_get_simple_settings()
|
||||
if simple_settings:
|
||||
names.extend([self.configure_get_name_for_simple_setting(simple)
|
||||
for simple in simple_settings])
|
||||
|
||||
if self.has_input_file_templates:
|
||||
if input_file_templates and self.has_input_file_templates:
|
||||
for template in self.normalize_input_file_templates():
|
||||
names.extend([
|
||||
template['setting_mode'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue