use jinja2 to render form templates w/ burnettk
This commit is contained in:
parent
d7d46d2140
commit
c69923e0fd
|
@ -2157,7 +2157,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
|
|||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "e395233463dec69fa7870815ff342096d7de3ea8899c54eac61ba334ff0b1c73"
|
||||
content-hash = "3fe7680583608ddd4ea93082b0c6c250507b53b2211218e00b2df01649bd6c6b"
|
||||
|
||||
[metadata.files]
|
||||
alabaster = [
|
||||
|
|
|
@ -49,6 +49,7 @@ types-pytz = "^2022.1.1"
|
|||
python-keycloak = "^2.5.0"
|
||||
APScheduler = "^3.9.1"
|
||||
types-requests = "^2.28.6"
|
||||
Jinja2 = "^3.1.2"
|
||||
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
|
|
@ -8,6 +8,7 @@ from typing import Union
|
|||
|
||||
import connexion # type: ignore
|
||||
import flask.wrappers
|
||||
import jinja2
|
||||
from flask import Blueprint
|
||||
from flask import g
|
||||
from flask import jsonify
|
||||
|
@ -747,6 +748,12 @@ def task_show(process_instance_id: int, task_id: str) -> flask.wrappers.Response
|
|||
)
|
||||
if ui_form_contents:
|
||||
task.form_ui_schema = ui_form_contents
|
||||
elif task.type == "ManualTask":
|
||||
if task.properties and task.data:
|
||||
if task.properties["instructionsForEndUser"]:
|
||||
task.properties["instructionsForEndUser"] = render_jinja_template(
|
||||
task.properties["instructionsForEndUser"], task.data
|
||||
)
|
||||
|
||||
return make_response(jsonify(task), 200)
|
||||
|
||||
|
@ -919,13 +926,14 @@ def prepare_form_data(
|
|||
return ""
|
||||
|
||||
file_contents = SpecFileService.get_data(process_model, form_file).decode("utf-8")
|
||||
return render_jinja_template(file_contents, task_data)
|
||||
|
||||
# trade out pieces like "{{variable_name}}" for the corresponding form data value
|
||||
for key, value in task_data.items():
|
||||
if isinstance(value, str) or isinstance(value, int):
|
||||
file_contents = file_contents.replace("{{" + key + "}}", str(value))
|
||||
|
||||
return file_contents
|
||||
def render_jinja_template(unprocessed_template: str, data: dict[str, Any]) -> str:
|
||||
"""Render_jinja_template."""
|
||||
jinja_environment = jinja2.Environment(autoescape=True)
|
||||
template = jinja_environment.from_string(unprocessed_template)
|
||||
return template.render(**data)
|
||||
|
||||
|
||||
def get_spiff_task_from_process_instance(
|
||||
|
|
Loading…
Reference in New Issue