single choice set default on embed

This commit is contained in:
Daniel Tsvetkov 2020-06-08 14:12:56 +02:00
parent f5e7f22f16
commit ac6eb101b5
3 changed files with 20 additions and 8 deletions

View File

@ -7,7 +7,7 @@
<title>Project</title>
<style type="text/css">
body {
font-family: Open Sans, Arial, sans-serif;
font-family: "Open Sans", Arial, sans-serif;
color: #444;
padding: 0 1em;
}
@ -45,7 +45,6 @@
input, textarea {
padding: 0.5em;
font-family: Open Sans, Arial sans-serif;
font-size: 1em;
box-sizing: border-box;
min-width: 300px;

View File

@ -1,15 +1,23 @@
<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
<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">Choose...</option>
[%- endif %]
{%- for sub_instance in model_views.[[ column.name ]].model.query.all() %}
<option value="{{ sub_instance.id }}" {% if instance and instance.id == sub_instance.id %}selected="selected"{% endif %}>{{ sub_instance }}</option>
{% 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', ] %]
@ -28,7 +36,8 @@
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endif %]
<br>
</td></tr>
[%- endfor %]
</table>
<input type="submit">
</form>

View File

@ -1,10 +1,13 @@
<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'] %]
<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 column.multiple %]multiple name="_m_n_[[ column.name|pluralize ]]"[% else %]name="[[ column.name ]]_id"[% endif %]>
{%- for sub_instance in model_views.[[ column.name ]].model.query.all() %}
<option value="{{ sub_instance.id }}"
[%- if column.multiple %]
@ -32,7 +35,8 @@
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endif %]
<br>
</td></tr>
[%- endfor %]
</table>
<input type="submit">
</form>