From 2a2ff721c11777ac6cefbfd5d1d060e5c62b4551 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 22 Feb 2018 11:18:11 -0600 Subject: [PATCH] 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 --- tailbone/views/batch/core.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 1d539dd2..b872e736 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -603,8 +603,8 @@ class BatchMasterView(MasterView): # TODO execution_options_schema = None - def make_execute_schema(self): - return self.execution_options_schema() + def make_execute_schema(self, batch): + return self.execution_options_schema().bind(batch=batch) def make_execute_form(self, batch=None, **kwargs): """ @@ -616,11 +616,15 @@ class BatchMasterView(MasterView): if self.has_execution_options(batch): if batch is None: batch = self.model_class - schema = self.make_execute_schema() + schema = self.make_execute_schema(batch) for field in schema: - key = 'batch.{}.execute_option.{}'.format(batch.batch_key, field.name) - if key in self.request.session: - defaults[field.name] = self.request.session[key] + + # 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) + if key in self.request.session: + defaults[field.name] = self.request.session[key] + else: schema = colander.Schema()