From dcc78194662fa00b0d30785a7c701f9647e3707a Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 9 May 2023 20:25:05 -0500 Subject: [PATCH] Misc. tweaks for "run import job" form --- tailbone/views/importing.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tailbone/views/importing.py b/tailbone/views/importing.py index bfbd82e9..acfddbf8 100644 --- a/tailbone/views/importing.py +++ b/tailbone/views/importing.py @@ -295,15 +295,42 @@ class ImportingView(MasterView): f.set_widget('models', dfwidget.SelectWidget(values=[(k, k) for k in keys], multiple=True, size=len(keys))) - # f.set_default('models', keys) - f.set_default('create', True) - f.set_default('update', True) - f.set_default('delete', False) + allow_create = True + allow_update = True + allow_delete = True + if len(keys) == 1: + importers = handler.get_importers().values() + importer = list(importers)[0] + allow_create = importer.allow_create + allow_update = importer.allow_update + allow_delete = importer.allow_delete + + if allow_create: + f.set_default('create', True) + else: + f.remove('create') + + if allow_update: + f.set_default('update', True) + else: + f.remove('update') + + if allow_delete: + f.set_default('delete', False) + else: + f.remove('delete') + # f.set_default('runas', self.rattail_config.get('rattail', 'runas.default') or '') + f.set_default('versioning', True) + f.set_helptext('versioning', "If set, version history will be updated as appropriate") + f.set_default('dry_run', False) + f.set_helptext('dry_run', "If set, data will not actually be written") + f.set_default('warnings', False) + f.set_helptext('warnings', "If set, will send an email if any diffs") def do_runjob(self, handler_info, form): handler = handler_info['_handler']