From 967b47876ff361c1eb77330f2f9d4844e64be3a1 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Mon, 8 Jun 2020 16:32:39 +0200 Subject: [PATCH] bool and many to many --- oshipka/persistance/__init__.py | 4 ++++ oshipka/webapp/views.py | 4 ++++ vm_gen/templates/html/_create.html | 18 +++++++++++++----- vm_gen/templates/html/_get.html | 6 ++++-- vm_gen/templates/html/_update.html | 14 ++++++++++++-- vm_gen/templates/model_py | 2 +- vm_gen/vm_gen.py | 12 +++++++++--- 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/oshipka/persistance/__init__.py b/oshipka/persistance/__init__.py index 8985883..3ae9748 100644 --- a/oshipka/persistance/__init__.py +++ b/oshipka/persistance/__init__.py @@ -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): diff --git a/oshipka/webapp/views.py b/oshipka/webapp/views.py index a33f3c5..db18448 100644 --- a/oshipka/webapp/views.py +++ b/oshipka/webapp/views.py @@ -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(): diff --git a/vm_gen/templates/html/_create.html b/vm_gen/templates/html/_create.html index 35f7394..d588e77 100644 --- a/vm_gen/templates/html/_create.html +++ b/vm_gen/templates/html/_create.html @@ -6,15 +6,18 @@ : [%- if column.type in ['relationship'] %] - + [% else %] + + [%- elif column.type in ['bool', 'boolean', ] %] + + [%- else %] [%- elif column.type in ['relationship'] %] [%- if column.multiple %] -
  • [[ column.name|pluralize ]]: {{ instance.[[ column.name|pluralize ]] }}
  • +
  • [[ column.name|pluralize ]]: {{ instance.[[ column.name|pluralize ]] }}
  • [%- else %]
  • [[ column.name ]]: {{ instance.[[ column.name ]] }}
  • [%- endif %] + [%- elif column.type in ['bool', 'boolean', ] %] +
  • [[ column.name ]]: {{ instance.[[ column.name ]]|bool }}
  • [%- else %] -
  • [[ column.name ]]: {{ instance.[[ column.name ]] }}
  • +
  • [[ column.name ]]: {{ instance.[[ column.name ]] }}
  • [%- endif %] {% endif %} [%- endfor %] \ No newline at end of file diff --git a/vm_gen/templates/html/_update.html b/vm_gen/templates/html/_update.html index 7dfe636..03d4d6c 100644 --- a/vm_gen/templates/html/_update.html +++ b/vm_gen/templates/html/_update.html @@ -6,8 +6,12 @@ : [%- if column.type in ['relationship'] %] - + + [%- endif %] {%- for sub_instance in model_views.[[ column.name ]].model.query.all() %}