conditionally show columns

This commit is contained in:
Daniel Tsvetkov 2020-08-12 13:28:04 +02:00
parent 0dbb20fdab
commit 0d02b47df5
4 changed files with 13 additions and 5 deletions

View File

@ -13,6 +13,7 @@ PaaS - creates easily deployable declarative web applications with (moslty) file
## TODO ## TODO
* [ ] [list] pagination of many items
* [ ] [prod_install] Download sensitive prompt * [ ] [prod_install] Download sensitive prompt
* [ ] [vm_gen] Auto generate dependency graph for `view_models/_process_order` * [ ] [vm_gen] Auto generate dependency graph for `view_models/_process_order`
* [ ] [auto_dns] Start and test `auto_dns.service` * [ ] [auto_dns] Start and test `auto_dns.service`

View File

@ -325,7 +325,10 @@ def populate_static(app):
if row_updates: if row_updates:
row.update(row_updates) row.update(row_updates)
if model_name == "User": if model_name == "User":
role_names = row.pop('role_names') if 'role_names' in row:
role_names = row.pop('role_names')
else:
role_names = ""
row['password'] = hash_password(row['password']) row['password'] = hash_password(row['password'])
user = user_datastore.create_user(**row) user = user_datastore.create_user(**row)
for role_name in role_names.split(';'): for role_name in role_names.split(';'):
@ -334,7 +337,7 @@ def populate_static(app):
else: else:
instance = create_model(model, row) instance = create_model(model, row)
db.session.add(instance) db.session.add(instance)
db.session.commit() db.session.commit()
def filter_m_n(serialized_args): def filter_m_n(serialized_args):

View File

@ -2,7 +2,8 @@
<input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('list_[[ name|camel_to_snake ]]') }}"/> <input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('list_[[ name|camel_to_snake ]]') }}"/>
<table> <table>
[%- for column in columns %] [%- for column in columns %]
<tr><td> {% 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>: <label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">{{ _("[[ column.name ]]") }}</label>:
</td><td> </td><td>
[%- if column.type in ['relationship'] %] [%- if column.type in ['relationship'] %]
@ -14,7 +15,7 @@
[%- if not column.secondary %] [%- if not column.secondary %]
<option selected="selected" value="">{{ _("Choose...") }}</option> <option selected="selected" value="">{{ _("Choose...") }}</option>
[%- endif %] [%- endif %]
{% if instance and instance.[[ column.name|pluralize ]] is defined %} {% if [[ column.name|pluralize ]] is not defined and instance and instance.[[ column.name|pluralize ]] is defined %}
{% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %} {% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %}
{% else %} {% else %}
{% set [[ column.name|pluralize ]] = model_views.[[ column.name ]].model.query.all() %} {% set [[ column.name|pluralize ]] = model_views.[[ column.name ]].model.query.all() %}
@ -49,6 +50,7 @@
/> />
[%- endif %] [%- endif %]
</td></tr> </td></tr>
{% endif %}
[%- endfor %] [%- endfor %]
</table> </table>
<input type="submit"> <input type="submit">

View File

@ -2,7 +2,8 @@
<input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}"/> <input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}"/>
<table> <table>
[%- for column in columns %] [%- for column in columns %]
<tr><td> {% 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>: <label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">{{ _("[[ column.name ]]") }}</label>:
</td><td> </td><td>
[%- if column.type in ['relationship'] %] [%- if column.type in ['relationship'] %]
@ -49,6 +50,7 @@
/> />
[%- endif %] [%- endif %]
</td></tr> </td></tr>
{% endif %}
[%- endfor %] [%- endfor %]
</table> </table>
<input type="submit"> <input type="submit">