oshipka/vm_gen/templates/html/_update.html
2020-07-08 14:38:55 +02:00

55 lines
2.9 KiB
HTML

<form action="{{ url_for('update_[[ name|camel_to_snake ]]', uuid=instance.id) }}" method="post">
<input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}"/>
<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'] %]
[%- if column.multiple %]
<input type="hidden" name="_m_n_[[ column.name|pluralize ]]" value="" />
<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 %]
{%- for sub_instance in model_views.[[ column.name ]].model.query.all() %}
<option value="{{ sub_instance.id }}"
[%- if column.multiple %]
{% if sub_instance in instance.[[ column.name|pluralize ]] %}selected="selected"{% endif %}>{{ sub_instance }}</option>
[%- else %]
{% if instance.[[ column.name ]]_id == sub_instance.id %}selected="selected"{% endif %}>{{ sub_instance }}</option>
[%- endif %]
{%- endfor %}
</select>
[%- elif column.type in ['choice', ] %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
name="[[ column.name ]]">
[%- for value, display in column.choices.items() %]
<option value="[[ value ]]" {% if 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 ]]"
value="{{ instance.[[ 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" name="_[[ column.name ]]" {% if instance.[[ column.name ]] %}checked=checked{% endif %}
value="1"
/>
[%- elif column.type in ['long_text', ] %]
<textarea id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
name="[[ column.name ]]">{{ instance.[[ column.name ]] }}</textarea>
[%- else %]
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
value="{{ instance.[[ column.name ]] }}"
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endif %]
</td></tr>
[%- endfor %]
</table>
<input type="submit">
</form>