nopaque/app/templates/wtf.html.j2

125 lines
4.1 KiB
Plaintext
Raw Normal View History

2020-10-23 06:51:46 +00:00
{% macro render_field(field) %}
{% if field.type == 'BooleanField' %}
{{ render_boolean_field(field, *args, **kwargs) }}
2024-11-20 14:56:29 +00:00
{% 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) }}
2020-10-23 06:51:46 +00:00
{% elif field.type == 'SubmitField' %}
{{ render_submit_field(field, *args, **kwargs) }}
2024-11-20 14:56:29 +00:00
{% elif field.type == 'TextAreaField' %}
{{ render_text_area_field(field, *args, **kwargs) }}
2020-10-23 06:51:46 +00:00
{% else %}
{{ render_generic_field(field, *args, **kwargs) }}
{% endif %}
{% endmacro %}
2024-11-20 14:56:29 +00:00
2020-10-23 06:51:46 +00:00
{% macro render_boolean_field(field) %}
2024-11-20 14:56:29 +00:00
<div>
2020-10-23 06:51:46 +00:00
<label>
2024-11-20 14:56:29 +00:00
<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 %}
2020-10-23 06:51:46 +00:00
</label>
2024-11-20 14:56:29 +00:00
</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>
2020-10-23 06:51:46 +00:00
{% for error in field.errors %}
2021-11-16 14:23:57 +00:00
<span class="helper-text error-color-text">{{ error }}</span>
2020-10-23 06:51:46 +00:00
{% endfor %}
</div>
{% endmacro %}
2024-11-20 14:56:29 +00:00
{% macro render_multiple_file_field(field) %}
2020-10-23 06:51:46 +00:00
{% set placeholder = kwargs.pop('placeholder', '') %}
2024-11-20 14:56:29 +00:00
2020-10-23 06:51:46 +00:00
<div class="file-field input-field">
<div class="btn">
<span>{{ field.label.text }}</span>
2024-11-20 14:56:29 +00:00
<input id="{{ field.id }}" name="{{ field.name }}" type="file" multiple>
2020-10-23 06:51:46 +00:00
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="{{ placeholder }}">
</div>
{% for error in field.errors %}
2021-11-16 14:23:57 +00:00
<span class="helper-text error-color-text">{{ error }}</span>
2020-10-23 06:51:46 +00:00
{% endfor %}
</div>
{% endmacro %}
2024-11-20 14:56:29 +00:00
{% macro render_integer_field(field) %}
2020-10-23 06:51:46 +00:00
<div class="input-field">
{% if 'material_icon' in kwargs %}
<i class="material-icons prefix">{{ kwargs.pop('material_icon') }}</i>
{% endif %}
2024-11-20 14:56:29 +00:00
<input class="validate" id="{{ field.id }}" name="{{ field.name }}" type="number">
<label for="{{ field.id }}">{{ field.label.text }}</label>
2020-10-23 06:51:46 +00:00
{% for error in field.errors %}
2021-11-16 14:23:57 +00:00
<span class="helper-text error-color-text">{{ error }}</span>
2020-10-23 06:51:46 +00:00
{% endfor %}
</div>
{% endmacro %}
2024-11-20 14:56:29 +00:00
2020-10-23 06:51:46 +00:00
{% macro render_submit_field(field) %}
2024-11-20 14:56:29 +00:00
<button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit">
2020-10-23 06:51:46 +00:00
{{ field.label.text }}
{% if 'material_icon' in kwargs %}
<i class="material-icons right">{{ kwargs.pop('material_icon') }}</i>
{% endif %}
</button>
{% endmacro %}
2024-11-20 14:56:29 +00:00
{% 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 %}