From 6cc509f5b45b77aeea5e0af922564e6639225df7 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 5 Feb 2018 14:24:49 -0600 Subject: [PATCH] Add `Form.show_cancel` flag, for hiding that button also use fields from schema by default, if fields not provided --- tailbone/forms2/core.py | 3 +++ tailbone/templates/forms2/deform.mako | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tailbone/forms2/core.py b/tailbone/forms2/core.py index 3c0a2a17..d5b3cb81 100644 --- a/tailbone/forms2/core.py +++ b/tailbone/forms2/core.py @@ -321,6 +321,7 @@ class Form(object): Base class for all forms. """ update_label = "Save" + show_cancel = True def __init__(self, fields=None, schema=None, request=None, readonly=False, readonly_fields=[], model_instance=None, model_class=None, nodes={}, enums={}, labels={}, renderers=None, @@ -331,6 +332,8 @@ class Form(object): if fields is not None: self.set_fields(fields) self.schema = schema + if self.fields is None and self.schema: + self.set_fields([f.name for f in self.schema]) self.request = request self.readonly = readonly self.readonly_fields = set(readonly_fields or []) diff --git a/tailbone/templates/forms2/deform.mako b/tailbone/templates/forms2/deform.mako index d30113d6..ce8a73d0 100644 --- a/tailbone/templates/forms2/deform.mako +++ b/tailbone/templates/forms2/deform.mako @@ -76,7 +76,9 @@ ${h.csrf_token(request)} ## % if form.creating and form.allow_successive_creates: ## ${h.submit('create_and_continue', form.successive_create_label)} ## % endif - ${h.link_to("Cancel", form.cancel_url, class_='button autodisable')} + % if getattr(form, 'show_cancel', True): + ${h.link_to("Cancel", form.cancel_url, class_='button autodisable')} + % endif % endif