mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
102 lines
3.5 KiB
Django/Jinja
102 lines
3.5 KiB
Django/Jinja
{% macro render_field(field) %}
|
|
{% if field.type == 'BooleanField' %}
|
|
{{ render_boolean_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'DecimalRangeField' %}
|
|
{{ render_decimal_range_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'SubmitField' %}
|
|
{{ render_submit_field(field, *args, **kwargs) }}
|
|
{% elif field.type in ['FileField', 'MultipleFileField'] %}
|
|
{{ render_file_field(field, *args, **kwargs) }}
|
|
{% else %}
|
|
{% if 'class_' in kwargs and 'validate' not in kwargs['class_'] %}
|
|
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' validate'}) %}
|
|
{% else %}
|
|
{% set tmp = kwargs.update({'class_': 'validate'}) %}
|
|
{% endif %}
|
|
{{ render_generic_field(field, *args, **kwargs) }}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro render_boolean_field(field) %}
|
|
{% set label = kwargs.pop('label', True) %}
|
|
<div class="switch">
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
<label>
|
|
{{ field(*args, **kwargs) }}
|
|
<span class="lever"></span>
|
|
{% if label %}
|
|
{{ field.label.text }}
|
|
{% endif %}
|
|
</label>
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
{% macro render_file_field(field) %}
|
|
{% set placeholder = kwargs.pop('placeholder', '') %}
|
|
<div class="file-field input-field">
|
|
<div class="btn">
|
|
<span>{{ field.label.text }}</span>
|
|
{{ field(*args, **kwargs) }}
|
|
</div>
|
|
<div class="file-path-wrapper">
|
|
<input class="file-path validate" type="text" placeholder="{{ placeholder }}">
|
|
</div>
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
{% macro render_generic_field(field) %}
|
|
{% if field.type == 'TextAreaField' and 'materialize-textarea' not in kwargs['class_'] %}
|
|
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' materialize-textarea'}) %}
|
|
{% elif field.type == 'IntegerField' %}
|
|
{% set tmp = kwargs.update({'type': 'number'}) %}
|
|
{% endif %}
|
|
{% set label = kwargs.pop('label', True) %}
|
|
<div class="input-field">
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
{{ field(*args, **kwargs) }}
|
|
{% if label %}
|
|
{{ field.label }}
|
|
{% endif %}
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
{% macro render_submit_field(field) %}
|
|
{% if 'class_' in kwargs and 'btn' not in kwargs['class_'] %}
|
|
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' btn'}) %}
|
|
{% else %}
|
|
{% set tmp = kwargs.update({'class_': 'btn'}) %}
|
|
{% endif %}
|
|
{% if 'waves-effect' not in kwargs['class_'] %}
|
|
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' waves-effect'}) %}
|
|
{% endif %}
|
|
{% if 'waves-light' not in kwargs['class_'] %}
|
|
{% set tmp = kwargs.update({'class_': kwargs['class_'] + ' waves-light'}) %}
|
|
{% endif %}
|
|
<button class="{{ kwargs['class_'] }}"
|
|
id="{{ field.id }}"
|
|
name="{{ field.name }}"
|
|
type="submit"
|
|
value="{{ field.label.text }}"
|
|
{% if 'style' in kwargs %}
|
|
style="{{ kwargs.pop('style') }}"
|
|
{% endif %}>
|
|
{{ field.label.text }}
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons right">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
</button>
|
|
{% endmacro %}
|