bool and many to many
This commit is contained in:
parent
c145eb7319
commit
967b47876f
@ -216,6 +216,10 @@ def register_filters(app):
|
||||
def timediff(diff):
|
||||
return time_ago(None, diff)
|
||||
|
||||
@app.template_filter('bool')
|
||||
def bool_filter(v):
|
||||
return bool(v)
|
||||
|
||||
|
||||
class Proxy(object):
|
||||
def __init__(self, proxied):
|
||||
|
@ -21,6 +21,10 @@ def default_get_form_func(vc):
|
||||
for k in request.form:
|
||||
if k.startswith('_m_n_'):
|
||||
vc.serialized_args[k] = request.form.getlist(k)
|
||||
elif k.startswith('_is_'):
|
||||
bool_values = request.form.getlist(k)
|
||||
bool_value = True if len(bool_values) == 2 else False
|
||||
vc.serialized_args[k[1:]] = bool_value
|
||||
vc.serialized_args.update(dict(filter(lambda k: not k[0].startswith("_"), dict(request.form).items())))
|
||||
to_delete = []
|
||||
for key, value in vc.serialized_args.items():
|
||||
|
@ -6,15 +6,18 @@
|
||||
<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 %]
|
||||
<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 instance.[[ column.name|pluralize ]] is not defined %}
|
||||
{% set [[ column.name|pluralize ]] = model_views.[[ column.name ]].model.query.all() %}
|
||||
{% else %}
|
||||
{% if instance and instance.[[ column.name|pluralize ]] is defined %}
|
||||
{% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %}
|
||||
{% else %}
|
||||
{% set [[ column.name|pluralize ]] = model_views.[[ 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>
|
||||
@ -32,6 +35,11 @@
|
||||
<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 ]]"
|
||||
/>
|
||||
[%- else %]
|
||||
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
|
||||
type="text" name="[[ column.name ]]" autocomplete="off"
|
||||
|
@ -7,12 +7,14 @@
|
||||
</video>
|
||||
[%- elif column.type in ['relationship'] %]
|
||||
[%- if column.multiple %]
|
||||
<li id="display-[[ name|camel_to_snake ]]-[[ column.name|pluralize ]]"><strong>[[ column.name|pluralize ]]</strong>: {{ instance.[[ column.name|pluralize ]] }}</li>
|
||||
<li id="display-[[ name|camel_to_snake ]]-[[ column.name ]]"><strong>[[ column.name|pluralize ]]</strong>: {{ instance.[[ column.name|pluralize ]] }}</li>
|
||||
[%- else %]
|
||||
<li id="display-[[ name|camel_to_snake ]]-[[ column.name ]]"><strong>[[ column.name ]]</strong>: {{ instance.[[ column.name ]] }}</li>
|
||||
[%- endif %]
|
||||
[%- elif column.type in ['bool', 'boolean', ] %]
|
||||
<li id="display-[[ name|camel_to_snake ]]-[[ column.name ]]"><strong>[[ column.name ]]</strong>: {{ instance.[[ column.name ]]|bool }}</li>
|
||||
[%- else %]
|
||||
<li id="display-[[ name|camel_to_snake ]]-[[ column.name ]]"><strong>[[ column.name ]]</strong>: {{ instance.[[ column.name ]] }}</li>
|
||||
<li id="display-[[ name|camel_to_snake ]]-[[ column.name ]]"><strong>[[ column.name ]]</strong>: {{ instance.[[ column.name ]] }}</li>
|
||||
[%- endif %]
|
||||
{% endif %}
|
||||
[%- endfor %]
|
@ -6,8 +6,12 @@
|
||||
<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 %]
|
||||
<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 %]
|
||||
@ -29,6 +33,12 @@
|
||||
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"
|
||||
/>
|
||||
[%- else %]
|
||||
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
|
||||
value="{{ instance.[[ column.name ]] }}"
|
||||
|
@ -1,4 +1,4 @@
|
||||
from oshipka.persistance import db, ModelController, index_service
|
||||
from oshipka.persistance import db, ModelController, index_service, LiberalBoolean
|
||||
|
||||
[%- if imports %]
|
||||
[%- for import in imports %]
|
||||
|
@ -47,7 +47,7 @@ def enrich_view_model(view_model):
|
||||
elif column_type in ['number', 'int', 'integer', ]:
|
||||
_column_type = 'db.Integer'
|
||||
elif column_type in ['bool', ] or column_name.startswith('is_'):
|
||||
_column_type = 'db.Boolean'
|
||||
_column_type = 'LiberalBoolean'
|
||||
elif column_type in ['relationship', ]:
|
||||
_column_type = 'relationship'
|
||||
multiple = column.get('multiple')
|
||||
@ -75,9 +75,15 @@ def process_model(view_model):
|
||||
template = env.get_template('model_py')
|
||||
model = autopep8.fix_code(template.render(**view_model), options=pep_options)
|
||||
_model_name = view_model.get('name')
|
||||
filename = "{}.py".format(camel_case_to_snake_case(_model_name.split('.yaml')[0]))
|
||||
with open(os.path.join(MODELS_PATH, filename), 'w+') as f:
|
||||
|
||||
model_camel = _model_name.split('.yaml')[0]
|
||||
model_snake = camel_case_to_snake_case(_model_name.split('.yaml')[0])
|
||||
with open(os.path.join(MODELS_PATH, "_{}.py".format(model_snake)), 'w+') as f:
|
||||
f.write(model)
|
||||
public_model = os.path.join(MODELS_PATH, "{}.py".format(model_snake))
|
||||
if not os.path.exists(public_model):
|
||||
with open(public_model, 'w+') as f:
|
||||
f.write("from webapp.models._{} import {}".format(model_snake, model_camel))
|
||||
|
||||
|
||||
def process_routes(view_model):
|
||||
|
Loading…
Reference in New Issue
Block a user