mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 03:14:19 +00:00
136 lines
4.0 KiB
Django/Jinja
136 lines
4.0 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 == 'StringField' %}
|
|
{{ render_string_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>
|
|
{{ field(*args, **kwargs) }}
|
|
<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>
|
|
{{ 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_integer_field(field) %}
|
|
{% set classes = kwargs.pop('class_', '').split(' ') %}
|
|
|
|
{% if 'validate' not in classes %}
|
|
{% set _ = classes.append('validate') %}
|
|
{% endif %}
|
|
|
|
{% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
|
|
|
|
{{ render_generic_field(field, *args, **kwargs) }}
|
|
{% 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>
|
|
{{ 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_string_field(field) %}
|
|
{% set classes = kwargs.pop('class_', '').split(' ') %}
|
|
|
|
{% if 'validate' not in classes %}
|
|
{% set _ = classes.append('validate') %}
|
|
{% endif %}
|
|
|
|
{% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
|
|
|
|
{{ render_generic_field(field, *args, **kwargs) }}
|
|
{% endmacro %}
|
|
|
|
|
|
{% macro render_submit_field(field) %}
|
|
<button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit" value="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) %}
|
|
{% set classes = kwargs.pop('class_', '').split(' ') %}
|
|
|
|
{% if 'materialize-textarea' not in classes %}
|
|
{% set _ = classes.append('materialize-textarea') %}
|
|
{% endif %}
|
|
|
|
{% if 'validate' not in classes %}
|
|
{% set _ = classes.append('validate') %}
|
|
{% endif %}
|
|
|
|
{% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
|
|
|
|
{{ render_generic_field(field, *args, **kwargs) }}
|
|
{% endmacro %}
|
|
|
|
|
|
{% macro render_generic_field(field) %}
|
|
<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 %}
|