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): def render(self, template=None, **kwargs):
if not template: if not template:
if self.readonly: if self.readonly and not self.use_buefy:
template = '/forms/form_readonly.mako' template = '/forms/form_readonly.mako'
elif self.use_buefy:
template = '/forms/form_buefy.mako'
else: else:
template = '/forms/form.mako' template = '/forms/form.mako'
context = kwargs context = kwargs
@ -727,7 +725,13 @@ class Form(object):
return self.deform_form 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: if dform is None:
dform = self.make_deform_form() 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,16 +1,24 @@
## -*- coding: utf-8; -*- ## -*- coding: utf-8; -*-
<script type="text/x-template" id="buefy-form-template"> <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.form(form.action_url, id=dform.formid, method='post', enctype='multipart/form-data', **form_kwargs)}
${h.csrf_token(request)} ${h.csrf_token(request)}
% endif % endif
<section> <section>
% for field in form.fields: % for field in form.fields:
% 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>
% elif field in dform:
<% field = dform[field] %> <% field = dform[field] %>
<b-field label="${form.get_label(field.name)}" <b-field horizontal
label="${form.get_label(field.name)}"
% if field.error: % if field.error:
type="is-danger" type="is-danger"
:message='${form.messages_json(field.error.messages())|n}' :message='${form.messages_json(field.error.messages())|n}'
@ -18,6 +26,7 @@
> >
${field.serialize(use_buefy=True)|n} ${field.serialize(use_buefy=True)|n}
</b-field> </b-field>
% endif
% endfor % endfor
</section> </section>
@ -25,7 +34,7 @@
% if buttons: % if buttons:
<br /> <br />
${buttons|n} ${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 /> <br />
<div class="buttons"> <div class="buttons">
${h.submit('save', getattr(form, 'submit_label', getattr(form, 'save_label', "Submit")), class_='button is-primary')} ${h.submit('save', getattr(form, 'submit_label', getattr(form, 'save_label', "Submit")), class_='button is-primary')}
@ -42,7 +51,7 @@
</div> </div>
% endif % endif
% if not readonly: % if not form.readonly:
${h.end_form()} ${h.end_form()}
% endif % endif
</script> </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/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/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/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__))} ${h.stylesheet_link(request.static_url('tailbone:static/css/diffs.css') + '?ver={}'.format(tailbone.__version__))}
<style type="text/css"> <style type="text/css">