Bind batch to its execution options schema, when applicable

so the batch can provide default values, etc.  this also tweaks logic for using
defaults from session storage, so that they don't take priority over batch values
This commit is contained in:
Lance Edgar 2018-02-22 11:18:11 -06:00
parent d75fe88c44
commit 2a2ff721c1

View file

@ -603,8 +603,8 @@ class BatchMasterView(MasterView):
# TODO # TODO
execution_options_schema = None execution_options_schema = None
def make_execute_schema(self): def make_execute_schema(self, batch):
return self.execution_options_schema() return self.execution_options_schema().bind(batch=batch)
def make_execute_form(self, batch=None, **kwargs): def make_execute_form(self, batch=None, **kwargs):
""" """
@ -616,11 +616,15 @@ class BatchMasterView(MasterView):
if self.has_execution_options(batch): if self.has_execution_options(batch):
if batch is None: if batch is None:
batch = self.model_class batch = self.model_class
schema = self.make_execute_schema() schema = self.make_execute_schema(batch)
for field in schema: for field in schema:
# if field does not yet have a default, maybe provide one from session storage
if field.default is colander.null:
key = 'batch.{}.execute_option.{}'.format(batch.batch_key, field.name) key = 'batch.{}.execute_option.{}'.format(batch.batch_key, field.name)
if key in self.request.session: if key in self.request.session:
defaults[field.name] = self.request.session[key] defaults[field.name] = self.request.session[key]
else: else:
schema = colander.Schema() schema = colander.Schema()