Add basic/generic Buefy support to the Form class

mostly just affects rendering, apparently backend logic needn't really change?
This commit is contained in:
Lance Edgar 2019-05-20 16:24:14 -05:00
parent a125e381a9
commit dfe0f49655
4 changed files with 12 additions and 3 deletions

View file

@ -340,7 +340,7 @@ class Form(object):
def __init__(self, fields=None, schema=None, request=None, mobile=False, readonly=False, readonly_fields=[],
model_instance=None, model_class=None, nodes={}, enums={}, labels={}, renderers=None,
hidden={}, widgets={}, defaults={}, validators={}, required={}, helptext={}, focus_spec=None,
action_url=None, cancel_url=None):
action_url=None, cancel_url=None, use_buefy=None):
self.fields = None
if fields is not None:
@ -374,6 +374,7 @@ class Form(object):
self.focus_spec = focus_spec
self.action_url = action_url
self.cancel_url = cancel_url
self.use_buefy = use_buefy
def __contains__(self, item):
return item in self.fields
@ -685,6 +686,8 @@ class Form(object):
if not template:
if self.readonly:
template = '/forms/form_readonly.mako'
elif self.use_buefy:
template = '/forms/form_buefy.mako'
else:
template = '/forms/form.mako'
context = kwargs

View file

@ -16,7 +16,7 @@
<div class="form-wrapper">
<p style="padding: 1em;">${report.__doc__}</p>
${form.render(template='/forms/form{}.mako'.format('_buefy' if use_buefy else ''))|n}
${form.render()|n}
</div><!-- form-wrapper -->
<ul id="context-menu">

View file

@ -97,6 +97,10 @@ class MasterView(View):
supports_prev_next = False
supports_import_batch_from_file = False
# whether or not Buefy is supported for CRUD forms. we're turning this on,
# "one view at a time" until it makes sense for that to be global default.
supports_buefy_forms = False
# quickie (search)
supports_quickie_search = False
expose_quickie_search = False
@ -2823,6 +2827,7 @@ class MasterView(View):
'readonly': self.viewing,
'model_class': getattr(self, 'model_class', None),
'action_url': self.request.current_route_url(_query=None),
'use_buefy': self.supports_buefy_forms and self.get_use_buefy(),
}
if self.creating:
kwargs.setdefault('cancel_url', self.get_index_url())

View file

@ -350,7 +350,8 @@ class GenerateReport(View):
schema.add(node)
form = forms.Form(schema=schema, request=self.request)
form = forms.Form(schema=schema, request=self.request,
use_buefy=self.get_use_buefy())
form.submit_label = "Generate this Report"
form.cancel_url = self.request.route_url('generate_report')