oshipka/vm_gen/templates/html/_create.html
2021-05-09 00:05:26 +02:00

60 lines
3.4 KiB
HTML

<form action="{{ url_for('create_[[ name|camel_to_snake ]]') }}" method="post" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('list_[[ name|camel_to_snake ]]') }}"/>
<table>
[%- for column in columns %]
{% if "[[ column.name ]]" not in disabled_columns %}
<tr {% if "[[ column.name ]]" in hidden_columns %}style="display: none;"{% endif %}><td>
<label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">{{ _("[[ column.name ]]") }}</label>:
</td><td>
[%- if column.type in ['relationship'] %]
[% if column.multiple %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]" name="_m_n_[[ column.name|pluralize ]]" multiple>
[% else %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]" name="[[ column.name ]]_id">
[%- endif %]
[%- if not column.secondary %]
<option selected="selected" value="">{{ _("Choose...") }}</option>
[%- endif %]
{% if [[ column.name|pluralize ]] is not defined and instance and instance.[[ column.name|pluralize ]] is defined %}
{% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %}
{% else %}
{% set [[ column.name|pluralize ]] = model_views.[[ column.to or column.name ]].model.query.all() %}
{% endif %}
{%- for sub_instance in [[ column.name|pluralize ]] %}
<option value="{{ sub_instance.id }}" {% if model_view.model_name == "[[ column.name ]]" and instance and instance.id == sub_instance.id %}selected="selected"{% endif %}>{{ sub_instance }}</option>
{%- endfor %}
</select>
[%- elif column.type in ['choice', ] %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
name="[[ column.name ]]">
<option selected="selected" value="">{{ _("Choose...") }}</option>
[%- for value, display in column.choices.items() %]
<option value="[[ value ]]" {% if instance and instance.[[ column.name ]] == "[[ value ]]" %}selected="selected"{% endif %}>[[ display ]]</option>
[%- endfor %]
</select>
[%- elif column.type in ['number', 'int', 'integer', ] %]
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
type="number" name="[[ column.name ]]"
/>
[%- elif column.type in ['bool', 'boolean', ] %]
<input type="hidden" name="_[[ column.name ]]" value="0" />
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
type="checkbox" value="1" name="_[[ column.name ]]"
/>
[%- elif column.type in ['long_text', ] %]
<textarea id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
name="[[ column.name ]]"></textarea>
[%- elif column.type in ['file', 'audio', 'video', 'image', 'picture', 'img', ] %]
<input type="file" name="_file_[[ column.name ]]" accept="[[ column.accept ]]">
[%- else %]
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endif %]
</td></tr>
{% endif %}
[%- endfor %]
</table>
<input type="submit">
</form>