nopaque/app/templates/wtf.html.j2

136 lines
4.0 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) }}
2024-12-16 08:45:19 +00:00
{% elif field.type == 'StringField' %}
{{ render_string_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-12-16 08:45:19 +00:00
{{ field(*args, **kwargs) }}
2024-11-20 14:56:29 +00:00
<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>
2024-12-16 08:45:19 +00:00
{{ field(*args, **kwargs) }}
2024-11-20 14:56:29 +00:00
</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
2024-12-16 08:45:19 +00:00
{% 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 %}
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-12-16 08:45:19 +00:00
{{ field(*args, **kwargs) }}
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
2024-12-16 08:45:19 +00:00
{% macro render_string_field(field) %}
{% set classes = kwargs.pop('class_', '').split(' ') %}
{% if 'validate' not in classes %}
{% set _ = classes.append('validate') %}
2020-10-23 06:51:46 +00:00
{% endif %}
2024-12-16 08:45:19 +00:00
{% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
{{ render_generic_field(field, *args, **kwargs) }}
2020-10-23 06:51:46 +00:00
{% endmacro %}
2024-11-20 14:56:29 +00:00
2020-10-23 06:51:46 +00:00
{% macro render_submit_field(field) %}
2024-12-16 08:57:18 +00:00
<button class="btn waves-effect waves-light" id="{{ field.id }}" name="{{ field.name }}" type="submit" value="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) %}
2024-12-16 08:45:19 +00:00
{% set classes = kwargs.pop('class_', '').split(' ') %}
{% if 'materialize-textarea' not in classes %}
{% set _ = classes.append('materialize-textarea') %}
2024-11-20 14:56:29 +00:00
{% endif %}
2024-12-16 08:45:19 +00:00
{% if 'validate' not in classes %}
{% set _ = classes.append('validate') %}
{% endif %}
{% set _ = kwargs.update({'class_': ' '.join(classes)}) %}
{{ render_generic_field(field, *args, **kwargs) }}
2024-11-20 14:56:29 +00:00
{% 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 %}