switch to self-rendered forms

This commit is contained in:
Jens Langhammer 2018-11-26 22:07:40 +01:00
parent 225dc112e7
commit c507e310b5
4 changed files with 64 additions and 2 deletions

View File

@ -0,0 +1,59 @@
{% load utils %}
{% csrf_token %}
{% for field in form %}
{% if field.help_text %}
<span>
{{ field.help_text }}
</span>
{% endif %}
<div class="form-group">
{% if field.field.widget|fieldtype == 'RadioSelect' %}
<label class="col-sm-2 control-label" {% if field.field.required %}class="required"{% endif %} for="{{ field.name }}-{{ forloop.counter0 }}">
{{ field.label }}
</label>
{% for c in field %}
<div class="radio col-sm-10">
<input type="radio" id="{{ field.name }}-{{ forloop.counter0 }}" name="{% if wizard %}{{ wizard.steps.current }}-{% endif %}{{ field.name }}" value="{{ c.data.value }}" {% if c.data.selected %} checked {% endif %}>
<label class="col-sm-2 control-label" for="{{ field.name }}-{{ forloop.counter0 }}">{{ c.choice_label }}</label>
</div>
{% endfor %}
{% elif field.field.widget|fieldtype == 'Select' %}
<label class="col-sm-2 control-label" {% if field.field.required %}class="required"{% endif %} for="{{ field.name }}-{{ forloop.counter0 }}">
{{ field.label }}
</label>
<div class="select col-sm-10">
{{ field }}
</div>
{% elif field.field.widget|fieldtype == 'CheckboxInput' %}
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
{{ field }} {{ field.label }}
</label>
</div>
</div>
{% else %}
<label class="col-sm-2 control-label" {% if field.field.required %}class="required"{% endif %} for="{{ field.name }}-{{ forloop.counter0 }}">
{{ field.label }}
</label>
<div class="col-sm-10">
{{ field|css_class:'form-control' }}
</div>
{% endif %}
{% for error in field.errors %}
<div class="alert alert-danger">
<div class="alert-items">
<div class="alert-item">
<div class="alert-icon-wrapper">
<clr-icon class="alert-icon" shape="exclamation-circle"></clr-icon>
</div>
<span class="alert-text">
{{ error }}
</span>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}

View File

@ -1,7 +1,6 @@
django>=2.0
django-reversion
django-model-utils
django-crispy-forms
djangorestframework
PyYAML
raven

View File

@ -56,7 +56,6 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'reversion',
'rest_framework',
'crispy_forms',
'passbook.core',
'passbook.admin',
'passbook.api',

View File

@ -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})