extend get view with template ctx

This commit is contained in:
Daniel Tsvetkov 2020-04-30 16:44:49 +02:00
parent f0de52fc14
commit c85f6c3622

View File

@ -30,7 +30,7 @@ def get_view(model_view, template, template_ctx_func=None):
def serialize_form():
return dict(request.form)
return dict(filter(lambda k: not k[0].startswith("__"), dict(request.form).items()))
def update_view(model_view, template):
@ -55,10 +55,11 @@ def update_view(model_view, template):
return inner
def create_view(model_view, template, post_add=None, post_create=None):
def create_view(model_view, template, template_ctx_func=None, post_add=None, post_create=None):
def inner():
if request.method == "GET":
return render_template(template)
template_ctx = template_ctx_func() if template_ctx_func else {}
return render_template(template, **template_ctx)
serialized_form = serialize_form()
_next = serialized_form.pop('_next') if '_next' in serialized_form else None