From 1f04ec0cea733c14be3903dd7055e7d78d5c7fec Mon Sep 17 00:00:00 2001 From: Tobias Schulmann Date: Sun, 24 Jun 2018 12:13:34 +1200 Subject: [PATCH] Add django-crispy-forms for BS4 support TODO: Remove django-bootstrap-form dependency, left to avoid breaking other parts. --- pinaxcon/settings.py | 4 ++ pinaxcon/templates/bootstrap4/field.html | 48 ++++++++++++++++++++++++ requirements.txt | 2 + 3 files changed, 54 insertions(+) create mode 100644 pinaxcon/templates/bootstrap4/field.html diff --git a/pinaxcon/settings.py b/pinaxcon/settings.py index 3e4f3a4d..61ffae20 100644 --- a/pinaxcon/settings.py +++ b/pinaxcon/settings.py @@ -234,8 +234,12 @@ INSTALLED_APPS = [ # testing and rollout "django_nose", "waffle", + + "crispy_forms", ] +CRISPY_TEMPLATE_PACK = "bootstrap4" + DEBUG_TOOLBAR_PANELS = [ 'debug_toolbar.panels.versions.VersionsPanel', 'debug_toolbar.panels.timer.TimerPanel', diff --git a/pinaxcon/templates/bootstrap4/field.html b/pinaxcon/templates/bootstrap4/field.html new file mode 100644 index 00000000..305e6493 --- /dev/null +++ b/pinaxcon/templates/bootstrap4/field.html @@ -0,0 +1,48 @@ +{% load crispy_forms_field %} + +{% if field.is_hidden %} + {{ field }} +{% else %} + {% if field|is_checkbox %} +
+ {% if label_class %} +
+ {% endif %} + {% endif %} + <{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="{% if not field|is_checkbox %}form-group{% if 'form-horizontal' in form_class %} row{% endif %}{% else %}form-check{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}"> + {% if field.label and not field|is_checkbox and form_show_labels %} + + {% endif %} + + {% if field|is_checkboxselectmultiple %} + {% include 'bootstrap4/layout/checkboxselectmultiple.html' %} + {% endif %} + + {% if field|is_radioselect %} + {% include 'bootstrap4/layout/radioselect.html' %} + {% endif %} + + {% if not field|is_checkboxselectmultiple and not field|is_radioselect %} + {% if field|is_checkbox and form_show_labels %} + + {% include 'bootstrap4/layout/help_text_and_errors.html' %} + {% else %} +
+ {% include 'bootstrap4/layout/help_text_and_errors.html' %} + {% crispy_field field %} +
+ {% endif %} + {% endif %} + + {% if field|is_checkbox %} + {% if label_class %} +
+ {% endif %} +
+ {% endif %} +{% endif %} diff --git a/requirements.txt b/requirements.txt index a134d2e7..64d2d1d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -49,3 +49,5 @@ django-waffle>=0.12.0 libsass==0.14.5 django-sass-processor==0.7 django-compressor==2.2 + +django-crispy-forms \ No newline at end of file