create vm + template gen

This commit is contained in:
Daniel Tsvetkov 2020-06-04 18:02:34 +02:00
parent 0942489056
commit 622b27bcce
9 changed files with 58 additions and 4 deletions

View File

@ -1,9 +1,9 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %} {% block content %}
<h1>Delete {{ model_name }}:{{ instance.uuid }} ?</h1> <h1>Delete {{ model_name }}:{{ instance.id }} ?</h1>
<form action="{{ url_for('delete_' + model_name, uuid=instance.uuid) }}" method="post"> <form action="{{ url_for('delete_' + model_name, uuid=instance.uuid) }}" method="post">
<input type="hidden" value="{{ request.args.next }}" name="_next"/> <input type="hidden" value="{{ request.args.next or url_for('list_' + model_name) }}" name="_next"/>
<input type="submit"/> <input type="submit"/>
</form> </form>
<a href="{{ request.args.next }}">Back</a> <a href="{{ request.args.next }}">Back</a>

View File

@ -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): 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(): def inner():
if request.method == "GET": if request.method == "GET":
template_ctx = template_ctx_func() if template_ctx_func else {} template_ctx = template_ctx_func() if template_ctx_func else {}

View File

@ -0,0 +1,11 @@
<h2>Create [[ name ]]</h2>
<form action="{{ url_for('create_[[ name|camel_to_snake ]]') }}" method="post">
<input type="hidden" name="_next" value="{{ url_for('list_[[ name|camel_to_snake ]]') }}"/>
[%- for column in columns %]
<label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>:
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endfor %]
<input type="submit">
</form>

View File

@ -0,0 +1,12 @@
<h2>Edit {% include "[[ name|camel_to_snake ]]/_title.html" %}</h2>
<form action="{{ url_for('update_[[ name|camel_to_snake ]]', uuid=instance.id) }}" method="post">
<input type="hidden" name="_next" value="{{ url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}"/>
[%- for column in columns %]
<label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>:
<input id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
value="{{ instance.[[ column.name ]] }}"
type="text" name="[[ column.name ]]" autocomplete="off"
/>
[%- endfor %]
<input type="submit">
</form>

View File

@ -0,0 +1,3 @@
<h2>{% include "[[ name|camel_to_snake ]]/_title.html" %}</h2>
<a href="{{ url_for('update_[[ name|camel_to_snake ]]', uuid=instance.id) }}">edit</a> |
<a href="{{ url_for('delete_[[ name|camel_to_snake ]]', uuid=instance.id) }}">delete</a>

View File

@ -1,3 +1,14 @@
<h2>[[ name|pluralize ]]</h2>
<a href="{{ url_for('create_[[ name|camel_to_snake ]]') }}">Create</a>
<br>
{% for instance in instances %} {% for instance in instances %}
<li><a href="{{ url_for('get_[[ name|camel_to_snake ]]', uuid=instance.uuid) }}">{{ instance.number }}</a></li> <li>
<a href="{{ url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}">
{% include "[[ name|camel_to_snake ]]/_title.html" %}</a>
|
[
<a href="{{ url_for('update_[[ name|camel_to_snake ]]', uuid=instance.id) }}">e</a> |
<a href="{{ url_for('delete_[[ name|camel_to_snake ]]', uuid=instance.id) }}">x</a>
]
</li>
{% endfor %} {% endfor %}

View File

@ -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 %]

View File

@ -0,0 +1,5 @@
{% extends "layout.html" %}
{% block content %}
{% include "[[ name|camel_to_snake ]]/_create.html" %}
{% endblock %}

View File

@ -106,7 +106,7 @@ if __name__ == "__main__":
MODELS_PATH = os.path.join(WEBAPP_PATH, "models") MODELS_PATH = os.path.join(WEBAPP_PATH, "models")
if not os.path.exists(MODELS_PATH): if not os.path.exists(MODELS_PATH):
os.makedirs(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( env = Environment(
loader=FileSystemLoader(searchpath=VM_TEMPLATES_PATH), loader=FileSystemLoader(searchpath=VM_TEMPLATES_PATH),