mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-27 03:44:19 +00:00
125 lines
4.1 KiB
Django/Jinja
125 lines
4.1 KiB
Django/Jinja
{% macro render_field(field) %}
|
|
{% if field.type == 'BooleanField' %}
|
|
{{ render_boolean_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'FileField' %}
|
|
{{ render_file_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'IntegerField' %}
|
|
{{ render_integer_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'MultipleFileField' %}
|
|
{{ render_multiple_file_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'SubmitField' %}
|
|
{{ render_submit_field(field, *args, **kwargs) }}
|
|
{% elif field.type == 'TextAreaField' %}
|
|
{{ render_text_area_field(field, *args, **kwargs) }}
|
|
{% else %}
|
|
{{ render_generic_field(field, *args, **kwargs) }}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
|
|
{% macro render_boolean_field(field) %}
|
|
<div>
|
|
<label>
|
|
<input id="{{ field.id }}" name="{{ field.name }}" type="checkbox">
|
|
<span>{{ field.label.text }}</span>
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</label>
|
|
</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>
|
|
<input id="{{ field.id }}" name="{{ field.name }}" type="file">
|
|
</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_multiple_file_field(field) %}
|
|
{% set placeholder = kwargs.pop('placeholder', '') %}
|
|
|
|
<div class="file-field input-field">
|
|
<div class="btn">
|
|
<span>{{ field.label.text }}</span>
|
|
<input id="{{ field.id }}" name="{{ field.name }}" type="file" multiple>
|
|
</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_integer_field(field) %}
|
|
<div class="input-field">
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
<input class="validate" id="{{ field.id }}" name="{{ field.name }}" type="number">
|
|
<label for="{{ field.id }}">{{ field.label.text }}</label>
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
|
|
{% macro render_submit_field(field) %}
|
|
<button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit">
|
|
{{ field.label.text }}
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons right">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
</button>
|
|
{% endmacro %}
|
|
|
|
|
|
{% macro render_text_area_field(field) %}
|
|
<div class="input-field">
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
<textarea class="materialize-textarea validate" id="{{ field.id }}" name="{{ field.name }}"></textarea>
|
|
<label for="{{ field.id }}">{{ field.label.text }}</label>
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
|
|
{% macro render_generic_field(field) %}
|
|
{% set classes_ = kwargs.pop('class_', '').split(' ') %}
|
|
{% if 'validate' not in classes_ %}
|
|
{% set _ = classes_.append('validate') %}
|
|
{% endif %}
|
|
{% set _ = kwargs.update({'class_': ' '.join(classes_)}) %}
|
|
|
|
<div class="input-field">
|
|
{% if 'material_icon' in kwargs %}
|
|
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
|
|
{% endif %}
|
|
{{ field(*args, **kwargs) }}
|
|
{{ field.label }}
|
|
{% for error in field.errors %}
|
|
<span class="helper-text error-color-text">{{ error }}</span>
|
|
{% endfor %}
|
|
</div>
|
|
{% endmacro %}
|