From 622b27bcce7994b2897ef2c434f62cf1bdab89c3 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Thu, 4 Jun 2020 18:02:34 +0200 Subject: [PATCH] create vm + template gen --- oshipka/webapp/templates/delete_instance.html | 4 ++-- oshipka/webapp/views.py | 2 ++ vm_gen/templates/html/_create.html | 11 +++++++++++ vm_gen/templates/html/_edit.html | 12 ++++++++++++ vm_gen/templates/html/_get.html | 3 +++ vm_gen/templates/html/_list.html | 13 ++++++++++++- vm_gen/templates/html/_title.html | 10 ++++++++++ vm_gen/templates/html/create.html | 5 +++++ vm_gen/vm_gen.py | 2 +- 9 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 vm_gen/templates/html/_create.html create mode 100644 vm_gen/templates/html/_title.html create mode 100644 vm_gen/templates/html/create.html diff --git a/oshipka/webapp/templates/delete_instance.html b/oshipka/webapp/templates/delete_instance.html index 0a16e3c..c29fb7b 100644 --- a/oshipka/webapp/templates/delete_instance.html +++ b/oshipka/webapp/templates/delete_instance.html @@ -1,9 +1,9 @@ {% extends "layout.html" %} {% block content %} -

Delete {{ model_name }}:{{ instance.uuid }} ?

+

Delete {{ model_name }}:{{ instance.id }} ?

- +
Back diff --git a/oshipka/webapp/views.py b/oshipka/webapp/views.py index 1dea866..6570d74 100644 --- a/oshipka/webapp/views.py +++ b/oshipka/webapp/views.py @@ -72,6 +72,8 @@ def update_view(model_view, template, pre_process_func=None, post_process_func=N def create_view(model_view, template, template_ctx_func=None, post_add=None, post_create=None): + template = template if template else "{}/create.html".format(model_view.model_name) + def inner(): if request.method == "GET": template_ctx = template_ctx_func() if template_ctx_func else {} diff --git a/vm_gen/templates/html/_create.html b/vm_gen/templates/html/_create.html new file mode 100644 index 0000000..063300e --- /dev/null +++ b/vm_gen/templates/html/_create.html @@ -0,0 +1,11 @@ +

Create [[ name ]]

+
+ + [%- for column in columns %] + : + + [%- endfor %] + +
\ No newline at end of file diff --git a/vm_gen/templates/html/_edit.html b/vm_gen/templates/html/_edit.html index e69de29..d3eab1c 100644 --- a/vm_gen/templates/html/_edit.html +++ b/vm_gen/templates/html/_edit.html @@ -0,0 +1,12 @@ +

Edit {% include "[[ name|camel_to_snake ]]/_title.html" %}

+
+ + [%- for column in columns %] + : + + [%- endfor %] + +
\ No newline at end of file diff --git a/vm_gen/templates/html/_get.html b/vm_gen/templates/html/_get.html index e69de29..10edc07 100644 --- a/vm_gen/templates/html/_get.html +++ b/vm_gen/templates/html/_get.html @@ -0,0 +1,3 @@ +

{% include "[[ name|camel_to_snake ]]/_title.html" %}

+edit | +delete \ No newline at end of file diff --git a/vm_gen/templates/html/_list.html b/vm_gen/templates/html/_list.html index dcfb8ae..7d0c018 100644 --- a/vm_gen/templates/html/_list.html +++ b/vm_gen/templates/html/_list.html @@ -1,3 +1,14 @@ +

[[ name|pluralize ]]

+Create +
{% for instance in instances %} -
  • {{ instance.number }}
  • +
  • + + {% include "[[ name|camel_to_snake ]]/_title.html" %} + | + [ + e | + x + ] +
  • {% endfor %} \ No newline at end of file diff --git a/vm_gen/templates/html/_title.html b/vm_gen/templates/html/_title.html new file mode 100644 index 0000000..733c227 --- /dev/null +++ b/vm_gen/templates/html/_title.html @@ -0,0 +1,10 @@ +[%- if display %] + [%- if display.primary %] + {{ instance.[[ display.primary ]] }} + [%- endif %] + [%- if display.secondary %] + - {{ instance.[[ display.secondary ]] }} + [%- endif %] +[%- else %] + [[ name ]] {{ instance.id }} +[%- endif %] \ No newline at end of file diff --git a/vm_gen/templates/html/create.html b/vm_gen/templates/html/create.html new file mode 100644 index 0000000..ac7fe3b --- /dev/null +++ b/vm_gen/templates/html/create.html @@ -0,0 +1,5 @@ +{% extends "layout.html" %} + +{% block content %} + {% include "[[ name|camel_to_snake ]]/_create.html" %} +{% endblock %} \ No newline at end of file diff --git a/vm_gen/vm_gen.py b/vm_gen/vm_gen.py index 0896481..3fc7bde 100644 --- a/vm_gen/vm_gen.py +++ b/vm_gen/vm_gen.py @@ -106,7 +106,7 @@ if __name__ == "__main__": MODELS_PATH = os.path.join(WEBAPP_PATH, "models") if not os.path.exists(MODELS_PATH): os.makedirs(MODELS_PATH) - HTML_TEMPLATES_PATH = os.path.join(WEBAPP_PATH, "templates_gen") + HTML_TEMPLATES_PATH = os.path.join(WEBAPP_PATH, "templates") env = Environment( loader=FileSystemLoader(searchpath=VM_TEMPLATES_PATH),