From fa992b245a5eb096ac2983f1017b52d292a45977 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Tue, 21 Aug 2018 11:13:50 +0100 Subject: [PATCH] Make forms more consistent and move the form templates to their own folder --- .../determinations/determination_form.html | 4 +++- .../funds/applicationsubmission_form.html | 16 ++-------------- .../apply/funds/templates/funds/fund_type.html | 2 +- .../review/templates/review/review_form.html | 15 +++------------ .../forms}/includes/field.html | 0 .../templates/forms/includes/form_errors.html | 13 +++++++++++++ .../apply/users/templates/users/account.html | 2 +- .../users/templates/users/change_password.html | 2 +- opentech/settings/base.py | 1 + 9 files changed, 25 insertions(+), 30 deletions(-) rename opentech/apply/{funds/templates/funds => templates/forms}/includes/field.html (100%) create mode 100644 opentech/apply/templates/forms/includes/form_errors.html diff --git a/opentech/apply/determinations/templates/determinations/determination_form.html b/opentech/apply/determinations/templates/determinations/determination_form.html index d6d0663b3..b0b09b54e 100644 --- a/opentech/apply/determinations/templates/determinations/determination_form.html +++ b/opentech/apply/determinations/templates/determinations/determination_form.html @@ -9,6 +9,8 @@ </div> </div> +{% include "forms/includes/form_errors.html" with form=form %} + <div class="wrapper wrapper--medium wrapper--inner-space-medium"> <form class="form form--with-p-tags" action="" method="post" novalidate> {{ form.media }} @@ -29,7 +31,7 @@ {% endifchanged %} {% if field.field %} - {% include "funds/includes/field.html" %} + {% include "forms/includes/field.html" %} {% else %} {{ field }} {% endif %} diff --git a/opentech/apply/funds/templates/funds/applicationsubmission_form.html b/opentech/apply/funds/templates/funds/applicationsubmission_form.html index 522fc4649..290009da0 100644 --- a/opentech/apply/funds/templates/funds/applicationsubmission_form.html +++ b/opentech/apply/funds/templates/funds/applicationsubmission_form.html @@ -7,19 +7,7 @@ </div> </div> -{% if form.errors or form.non_field_errors %} -<div class="wrapper wrapper--medium wrapper--error"> - <svg class="icon icon--error"><use xlink:href="#error"></use></svg> - <h5 class="heading heading--no-margin heading--regular">There were some errors with your form. Please amend the fields highlighted below</h5> - {% if form.non_field_errors %} - <ul> - {% for error in form.non_field_errors %} - <li class="error">{{ error }}</li> - {% endfor %} - </ul> - {% endif %} -</div> -{% endif %} +{% include "forms/includes/form_errors.html" with form=form %} <div class="wrapper wrapper--light-grey-bg wrapper--form wrapper--sidebar"> <div> @@ -29,7 +17,7 @@ {% for field in form %} {% if field.field %} - {% include "funds/includes/field.html" %} + {% include "forms/includes/field.html" %} {% else %} {{ field }} {% endif %} diff --git a/opentech/apply/funds/templates/funds/fund_type.html b/opentech/apply/funds/templates/funds/fund_type.html index 1415fd1eb..126f364f7 100644 --- a/opentech/apply/funds/templates/funds/fund_type.html +++ b/opentech/apply/funds/templates/funds/fund_type.html @@ -32,7 +32,7 @@ {% for field in form %} {% if field.field %} - {% include "funds/includes/field.html" %} + {% include "forms/includes/field.html" %} {% else %} {{ field }} {% endif %} diff --git a/opentech/apply/review/templates/review/review_form.html b/opentech/apply/review/templates/review/review_form.html index 16a0db109..d87628e52 100644 --- a/opentech/apply/review/templates/review/review_form.html +++ b/opentech/apply/review/templates/review/review_form.html @@ -8,23 +8,14 @@ </div> </div> +{% include "forms/includes/form_errors.html" with form=form %} + <div class="wrapper wrapper--medium wrapper--inner-space-medium"> {% if not has_submitted_review %} <form class="form form--with-p-tags form--scoreable" action="" method="post" novalidate> {{ form.media }} {% csrf_token %} - {% if form.non_field_errors %} - <div class="messages"> - <ul> - {% for error in form.non_field_errors %} - <li class="error">{{ error }}</li> - {% endfor %} - </ul> - </div> - {% endif %} - - {% for hidden in form.hidden_fields %} {{ hidden }} {% endfor %} @@ -40,7 +31,7 @@ {% endifchanged %} {% if field.field %} - {% include "funds/includes/field.html" %} + {% include "forms/includes/field.html" %} {% else %} {{ field }} {% endif %} diff --git a/opentech/apply/funds/templates/funds/includes/field.html b/opentech/apply/templates/forms/includes/field.html similarity index 100% rename from opentech/apply/funds/templates/funds/includes/field.html rename to opentech/apply/templates/forms/includes/field.html diff --git a/opentech/apply/templates/forms/includes/form_errors.html b/opentech/apply/templates/forms/includes/form_errors.html new file mode 100644 index 000000000..59bfb2ce4 --- /dev/null +++ b/opentech/apply/templates/forms/includes/form_errors.html @@ -0,0 +1,13 @@ +{% if form.errors or form.non_field_errors %} +<div class="wrapper wrapper--medium wrapper--error"> + <svg class="icon icon--error"><use xlink:href="#error"></use></svg> + <h5 class="heading heading--no-margin heading--regular">There were some errors with your form. Please amend the fields highlighted below</h5> + {% if form.non_field_errors %} + <ul> + {% for error in form.non_field_errors %} + <li class="error">{{ error }}</li> + {% endfor %} + </ul> + {% endif %} +</div> +{% endif %} diff --git a/opentech/apply/users/templates/users/account.html b/opentech/apply/users/templates/users/account.html index 0f9c73f4b..fafb3656f 100644 --- a/opentech/apply/users/templates/users/account.html +++ b/opentech/apply/users/templates/users/account.html @@ -16,7 +16,7 @@ <form action="" method="post" class="form"> {% csrf_token %} {% for field in form %} - {% include "funds/includes/field.html" %} + {% include "forms/includes/field.html" %} {% endfor %} <button class="button button--primary" type="submit">{% trans "Update Profile" %}</button> </form> diff --git a/opentech/apply/users/templates/users/change_password.html b/opentech/apply/users/templates/users/change_password.html index ba6419db4..3045f6511 100644 --- a/opentech/apply/users/templates/users/change_password.html +++ b/opentech/apply/users/templates/users/change_password.html @@ -28,7 +28,7 @@ {% csrf_token %} {% for field in form %} - {% include "funds/includes/field.html" %} + {% include "forms/includes/field.html" %} {% endfor %} <button class="button button--primary" type="submit">{% trans 'Reset password' %}</button> diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 0fec18577..f197ea6c2 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -105,6 +105,7 @@ TEMPLATES = [ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(PROJECT_DIR, 'templates'), + os.path.join(PROJECT_DIR, 'apply', 'templates'), ], 'APP_DIRS': True, 'OPTIONS': { -- GitLab