create vm + template gen
This commit is contained in:
parent
0942489056
commit
622b27bcce
@ -1,9 +1,9 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% 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">
|
||||
<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"/>
|
||||
</form>
|
||||
<a href="{{ request.args.next }}">Back</a>
|
||||
|
@ -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 {}
|
||||
|
11
vm_gen/templates/html/_create.html
Normal file
11
vm_gen/templates/html/_create.html
Normal 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>
|
@ -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>
|
@ -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>
|
@ -1,3 +1,14 @@
|
||||
<h2>[[ name|pluralize ]]</h2>
|
||||
<a href="{{ url_for('create_[[ name|camel_to_snake ]]') }}">Create</a>
|
||||
<br>
|
||||
{% 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 %}
|
10
vm_gen/templates/html/_title.html
Normal file
10
vm_gen/templates/html/_title.html
Normal 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 %]
|
5
vm_gen/templates/html/create.html
Normal file
5
vm_gen/templates/html/create.html
Normal file
@ -0,0 +1,5 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% include "[[ name|camel_to_snake ]]/_create.html" %}
|
||||
{% endblock %}
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user