From c507e310b58db4c2f320fb96ce8160d027370557 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 26 Nov 2018 22:07:40 +0100 Subject: [PATCH] switch to self-rendered forms --- passbook/admin/templates/blocks/form.html | 59 +++++++++++++++++++++++ passbook/core/requirements.txt | 1 - passbook/core/settings.py | 1 - passbook/lib/templatetags/utils.py | 5 ++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 passbook/admin/templates/blocks/form.html diff --git a/passbook/admin/templates/blocks/form.html b/passbook/admin/templates/blocks/form.html new file mode 100644 index 000000000..6f34c49c3 --- /dev/null +++ b/passbook/admin/templates/blocks/form.html @@ -0,0 +1,59 @@ +{% load utils %} + +{% csrf_token %} +{% for field in form %} +{% if field.help_text %} + + {{ field.help_text }} + +{% endif %} +
+ {% if field.field.widget|fieldtype == 'RadioSelect' %} + + {% for c in field %} +
+ + +
+ {% endfor %} + {% elif field.field.widget|fieldtype == 'Select' %} + +
+ {{ field }} +
+ {% elif field.field.widget|fieldtype == 'CheckboxInput' %} +
+
+ +
+
+ {% else %} + +
+ {{ field|css_class:'form-control' }} +
+ {% endif %} + {% for error in field.errors %} +
+
+
+
+ +
+ + {{ error }} + +
+
+
+ {% endfor %} +
+{% endfor %} diff --git a/passbook/core/requirements.txt b/passbook/core/requirements.txt index 19b8526dc..ac93703d6 100644 --- a/passbook/core/requirements.txt +++ b/passbook/core/requirements.txt @@ -1,7 +1,6 @@ django>=2.0 django-reversion django-model-utils -django-crispy-forms djangorestframework PyYAML raven diff --git a/passbook/core/settings.py b/passbook/core/settings.py index 71a20b539..76e14027a 100644 --- a/passbook/core/settings.py +++ b/passbook/core/settings.py @@ -56,7 +56,6 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'reversion', 'rest_framework', - 'crispy_forms', 'passbook.core', 'passbook.admin', 'passbook.api', diff --git a/passbook/lib/templatetags/utils.py b/passbook/lib/templatetags/utils.py index ec1b9b7e2..c4befd2fa 100644 --- a/passbook/lib/templatetags/utils.py +++ b/passbook/lib/templatetags/utils.py @@ -157,3 +157,8 @@ def related_models(context, model_path): def unslug(_input): """Convert slugs back into normal strings""" return _input.replace('-', ' ').replace('_', ' ') + + +@register.filter(name='css_class') +def css_class(field, css): + return field.as_widget(attrs={"class": css})