Add some smarts when making batch execution form schema

in some cases `has_execution_options()` may return True but the base
view class may not need to provide any options itself (i.e. subclass
is responsible for declaring the view has options).
This commit is contained in:
Lance Edgar 2021-12-15 15:02:28 -06:00
parent ca57bd3572
commit f49fdebd98

View file

@ -786,28 +786,30 @@ class BatchMasterView(MasterView):
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
use_buefy = self.get_use_buefy() use_buefy = self.get_use_buefy()
schema = None
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(batch) schema = self.make_execute_schema(batch)
for field in schema: if schema:
for field in schema:
# if field does not yet have a default, maybe provide one from session storage # if field does not yet have a default, maybe provide one from session storage
if field.default is colander.null: 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]
# make sure field label is preserved # make sure field label is preserved
if field.title: if field.title:
labels = kwargs.setdefault('labels', {}) labels = kwargs.setdefault('labels', {})
labels[field.name] = field.title labels[field.name] = field.title
# auto-convert select widgets for buefy theme # auto-convert select widgets for buefy theme
if use_buefy and isinstance(field.widget, forms.widgets.PlainSelectWidget): if use_buefy and isinstance(field.widget, forms.widgets.PlainSelectWidget):
field.widget = dfwidget.SelectWidget(values=field.widget.values) field.widget = dfwidget.SelectWidget(values=field.widget.values)
else: if not schema:
schema = colander.Schema() schema = colander.Schema()
kwargs['use_buefy'] = use_buefy kwargs['use_buefy'] = use_buefy