oshipka/vm_gen/templates/html/_create.html
2020-06-08 15:39:23 +02:00

44 lines
2.3 KiB
HTML

<form action="{{ url_for('create_[[ name|camel_to_snake ]]') }}" method="post">
<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 %]
<tr><td>
<label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>:
</td><td>
[%- if column.type in ['relationship'] %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]" [% if column.multiple %]multiple
name="_m_n_[[ column.name|pluralize ]]"[% else %]name="[[ column.name ]]_id"[%- endif %]>
[%- if not column.secondary %]
<option selected="selected" value="">Choose...</option>
[%- endif %]
{% if instance.[[ column.name|pluralize ]] is not defined %}
{% set [[ column.name|pluralize ]] = model_views.[[ column.name ]].model.query.all() %}
{% else %}
{% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %}
{% 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 ]]_id">
<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 ]]"
/>
[%- else %]
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endif %]
</td></tr>
[%- endfor %]
</table>
<input type="submit">
</form>