From f49fdebd98989ca904e3920f5f39674d47a8d54c Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 15 Dec 2021 15:02:28 -0600 Subject: [PATCH] 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). --- tailbone/views/batch/core.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 83412761..29aa308e 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -786,28 +786,30 @@ class BatchMasterView(MasterView): route_prefix = self.get_route_prefix() use_buefy = self.get_use_buefy() + schema = None if self.has_execution_options(batch): if batch is None: batch = self.model_class 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.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] + # 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] - # make sure field label is preserved - if field.title: - labels = kwargs.setdefault('labels', {}) - labels[field.name] = field.title + # make sure field label is preserved + if field.title: + labels = kwargs.setdefault('labels', {}) + labels[field.name] = field.title - # auto-convert select widgets for buefy theme - if use_buefy and isinstance(field.widget, forms.widgets.PlainSelectWidget): - field.widget = dfwidget.SelectWidget(values=field.widget.values) + # auto-convert select widgets for buefy theme + if use_buefy and isinstance(field.widget, forms.widgets.PlainSelectWidget): + field.widget = dfwidget.SelectWidget(values=field.widget.values) - else: + if not schema: schema = colander.Schema() kwargs['use_buefy'] = use_buefy