Improve readonly form templates somewhat, for Buefy

progress at least, more polish needed yet
This commit is contained in:
Lance Edgar 2019-05-21 12:14:49 -05:00
parent 40e957fff2
commit fbf3ee5cd1
5 changed files with 45 additions and 22 deletions

View file

@ -684,10 +684,8 @@ class Form(object):
def render(self, template=None, **kwargs):
if not template:
if self.readonly:
if self.readonly and not self.use_buefy:
template = '/forms/form_readonly.mako'
elif self.use_buefy:
template = '/forms/form_buefy.mako'
else:
template = '/forms/form.mako'
context = kwargs
@ -727,7 +725,13 @@ class Form(object):
return self.deform_form
def render_deform(self, dform=None, template='/forms/deform.mako', **kwargs):
def render_deform(self, dform=None, template=None, **kwargs):
if not template:
if self.use_buefy:
template = '/forms/deform_buefy.mako'
else:
template = '/forms/deform.mako'
if dform is None:
dform = self.make_deform_form()

View file

@ -0,0 +1,15 @@
/******************************
* forms
******************************/
/* TODO: replace this with bulma equivalent */
.form {
padding-left: 5em;
}
.field.is-horizontal .field-label .label {
text-align: left;
white-space: nowrap;
width: 18em;
}

View file

@ -1,23 +1,32 @@
## -*- coding: utf-8; -*-
<script type="text/x-template" id="buefy-form-template">
% if not readonly:
% if not form.readonly:
${h.form(form.action_url, id=dform.formid, method='post', enctype='multipart/form-data', **form_kwargs)}
${h.csrf_token(request)}
% endif
<section>
% for field in form.fields:
<% field = dform[field] %>
% if form.readonly or (field not in dform and field in form.readonly_fields):
<b-field horizontal
label="${form.get_label(field)}">
${form.render_field_value(field)}
</b-field>
<b-field label="${form.get_label(field.name)}"
% if field.error:
type="is-danger"
:message='${form.messages_json(field.error.messages())|n}'
% endif
>
${field.serialize(use_buefy=True)|n}
</b-field>
% elif field in dform:
<% field = dform[field] %>
<b-field horizontal
label="${form.get_label(field.name)}"
% if field.error:
type="is-danger"
:message='${form.messages_json(field.error.messages())|n}'
% endif
>
${field.serialize(use_buefy=True)|n}
</b-field>
% endif
% endfor
</section>
@ -25,7 +34,7 @@
% if buttons:
<br />
${buttons|n}
% elif not readonly and (buttons is Undefined or (buttons is not None and buttons is not False)):
% elif not form.readonly and (buttons is Undefined or (buttons is not None and buttons is not False)):
<br />
<div class="buttons">
${h.submit('save', getattr(form, 'submit_label', getattr(form, 'save_label', "Submit")), class_='button is-primary')}
@ -42,7 +51,7 @@
</div>
% endif
% if not readonly:
% if not form.readonly:
${h.end_form()}
% endif
</script>

View file

@ -1,5 +0,0 @@
## -*- coding: utf-8; -*-
<div class="form">
${form.render_deform(template='/forms/deform_buefy.mako')|n}
</div>

View file

@ -339,7 +339,7 @@
${h.stylesheet_link(request.static_url('tailbone:static/themes/falafel/css/grids.rowstatus.css') + '?ver={}'.format(tailbone.__version__))}
## ${h.stylesheet_link(request.static_url('tailbone:static/css/filters.css') + '?ver={}'.format(tailbone.__version__))}
${h.stylesheet_link(request.static_url('tailbone:static/themes/falafel/css/filters.css') + '?ver={}'.format(tailbone.__version__))}
${h.stylesheet_link(request.static_url('tailbone:static/themes/bobcat/css/forms.css') + '?ver={}'.format(tailbone.__version__))}
${h.stylesheet_link(request.static_url('tailbone:static/themes/falafel/css/forms.css') + '?ver={}'.format(tailbone.__version__))}
${h.stylesheet_link(request.static_url('tailbone:static/css/diffs.css') + '?ver={}'.format(tailbone.__version__))}
<style type="text/css">