|
@@ -0,0 +1,61 @@
|
|
|
+{# Forms macros for rendering forms and fields and stuff in templates. #}
|
|
|
+
|
|
|
+{% macro hiddens(form) -%}
|
|
|
+ <input type="hidden" name="{{ csrf_id }}" value="{{ csrf_token }}">
|
|
|
+ {% for field in form.hidden_fields() %}
|
|
|
+ <input type="hidden" name="{{ field.html_name }}" value="{{ field.value() }}">
|
|
|
+ {% endfor %}
|
|
|
+{%- endmacro %}
|
|
|
+
|
|
|
+{% macro row(_field, label=None, help_text=None, width=12, attrs=None) -%}
|
|
|
+ <div id="{{ field.html_name }}-control-group" class="control-group{% if _field.errors %} error{% endif %}">
|
|
|
+ <label class="control-label" for="id_{{ field.html_name }}">{% if label %}{{ label }}{% elif _field.label %}{{ _field.label }}{% else %}{{ _field.html_name }}{% endif %}</label>
|
|
|
+ <div class="controls">
|
|
|
+ {% if _field.field.widget.__class__.__name__ == 'CheckboxInput' %}
|
|
|
+ <label class="checkbox">
|
|
|
+ {{ field(_field, width=width, attrs=attrs)|trim }}
|
|
|
+ {% if help_text %}
|
|
|
+ {{ help_text }}
|
|
|
+ {% elif _field.help_text %}
|
|
|
+ {{ _field.help_text }}
|
|
|
+ {% endif %}
|
|
|
+ </label>
|
|
|
+ {% else %}
|
|
|
+ {{ field(_field, width=width, attrs=attrs)|trim }}
|
|
|
+ {% endif %}
|
|
|
+ {% for error in _field.errors %}
|
|
|
+ <p class="help-block" style="font-weight: bold;">{{ error }}</p>
|
|
|
+ {% endfor %}
|
|
|
+ {% if _field.field.widget.__class__.__name__ != 'CheckboxInput' %}
|
|
|
+ {% if help_text %}
|
|
|
+ <p class="help-block">{{ help_text }}</p>
|
|
|
+ {% elif _field.help_text %}
|
|
|
+ <p class="help-block">{{ _field.help_text }}</p>
|
|
|
+ {% endif %}
|
|
|
+ {% endif %}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+{%- endmacro %}
|
|
|
+
|
|
|
+{% macro field(_field, attrs=None, width=8) -%}
|
|
|
+{% set widget = _field.field.widget.__class__.__name__ %}
|
|
|
+{% set context = _field.field.widget.get_context(_field.html_name, _field.value(), attrs=attrs) %}
|
|
|
+{% if not 'class' in context['attrs'] and not widget == 'CheckboxInput' %}
|
|
|
+{% do context['attrs'].update({'class': ('span' ~ width)}) %}
|
|
|
+{% endif %}
|
|
|
+{{ _input(_field, context) }}
|
|
|
+{%- endmacro %}
|
|
|
+
|
|
|
+{% macro attributes(attrs) -%}
|
|
|
+{% for name, value in attrs.items() %} {{ name }}{% if value != True %}="{{ value }}"{% endif %}{% endfor %}
|
|
|
+{%- endmacro %}
|
|
|
+
|
|
|
+{% macro _input(_field, context) -%}
|
|
|
+<input type="{{ context.type }}" id="id_{{ context.name }}" name="{{ context.name }}" {{ attributes(context.attrs)|trim }}{% if 'value' in context and context.value|length > 0 %} value="{{ context.value }}"{% endif %}>
|
|
|
+{%- endmacro %}
|
|
|
+
|
|
|
+{% macro _textarea(_field, context) -%}
|
|
|
+{%- endmacro %}
|
|
|
+
|
|
|
+{% macro _select(_field, context) -%}
|
|
|
+{%- endmacro %}
|