From 286213026982435e6e87cdbbd5dddcd80e925b91 Mon Sep 17 00:00:00 2001 From: Jocelyn Delalande Date: Wed, 1 Feb 2017 19:41:55 +0100 Subject: [PATCH] Adapt to bootstrap 4 forms - Adapt to BS4 class names and hierarchy - Redesign some forms to have the label above the input (mobile-friendly) - For the remaining inline form (add bill), use the grid, as BS no longer provides inline form alignment helpers --- budget/forms.py | 4 ++-- budget/templates/display_errors.html | 2 +- budget/templates/forms.html | 22 +++++++++++++--------- budget/templates/home.html | 4 ++-- budget/templates/list_bills.html | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/budget/forms.py b/budget/forms.py index 77a5ec2..adf3de7 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -19,14 +19,14 @@ def select_multi_checkbox(field, ul_class='', **kwargs): choice_id = u'toggleField' js_function = u'toggle();' options = dict(kwargs, id=choice_id, onclick=js_function) - html.append(u'

%s | %s

'% (_("Select all"), _("Select none"))) + html.append(u'

%s | %s

'% (_("Select all"), _("Select none"))) for value, label, checked in field.iter_choices(): choice_id = u'%s-%s' % (field_id, value) options = dict(kwargs, name=field.name, value=value, id=choice_id) if checked: options['checked'] = 'checked' - html.append(u'

' + html.append(u'

' % (choice_id, ' ' % html_params(**options), label)) html.append(u'') return u''.join(html) diff --git a/budget/templates/display_errors.html b/budget/templates/display_errors.html index bc65a3a..9e19605 100644 --- a/budget/templates/display_errors.html +++ b/budget/templates/display_errors.html @@ -1,5 +1,5 @@ {% for field_name, field_errors in form.errors.items() if field_errors %} {% for error in field_errors %} -

{{ form[field_name].label.text }}: {{ error }}

+

{{ form[field_name].label.text }}: {{ error }}

{% endfor %} {% endfor %} diff --git a/budget/templates/forms.html b/budget/templates/forms.html index 07e5b3d..cf599a9 100644 --- a/budget/templates/forms.html +++ b/budget/templates/forms.html @@ -1,9 +1,13 @@ -{% macro input(field, multiple=False, class=None) -%} -
+{% macro input(field, multiple=False, class='form-control', inline=False) -%} +
{% if field.type != "SubmitField" %} - {{ field.label(class="control-label") }} + {% if inline %} + {{ field.label(class="col-3") }} + {% else %} + {{ field.label() }} + {% endif %} {% endif %} -
+
{% if multiple == True %} {{ field(multiple=True, class=class) }} {% else %} @@ -77,11 +81,11 @@ {% if title %}{% if edit %}{{ _("Edit this bill") }} {% else %}{{ _("Add a bill") }} {% endif %}{% endif %} {% include "display_errors.html" %} {{ form.hidden_tag() }} - {{ input(form.date, class="datepicker") }} - {{ input(form.what) }} - {{ input(form.payer) }} - {{ input(form.amount) }} - {{ input(form.payed_for) }} + {{ input(form.date, class="form-control datepicker", inline=True) }} + {{ input(form.what, inline=True) }} + {{ input(form.payer, inline=True, class="form-control custom-select") }} + {{ input(form.amount, inline=True) }} + {{ input(form.payed_for, inline=True, class="form-check-input") }}
{{ form.submit(class="btn btn-primary") }} diff --git a/budget/templates/home.html b/budget/templates/home.html index b9a2b46..e6d7932 100644 --- a/budget/templates/home.html +++ b/budget/templates/home.html @@ -20,7 +20,7 @@
-
+
{{ _("Log to an existing project") }}... {{ forms.authenticate(auth_form, home=True) }}
@@ -32,7 +32,7 @@
-
+
...{{ _("or create a new one") }} {{ forms.create_project(project_form, home=True) }}
diff --git a/budget/templates/list_bills.html b/budget/templates/list_bills.html index 72b9032..aacc128 100644 --- a/budget/templates/list_bills.html +++ b/budget/templates/list_bills.html @@ -58,7 +58,7 @@ {% block sidebar %}