diff --git a/README.md b/README.md index 0fa5cc0..947e02e 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,14 @@ Containers should be running to run tests via docker. docker compose -f docker-compose.local.yml -f docker-compose.override.yml up -d docker compose exec -T zwd-backend python manage.py test /app/apps ``` + +## Dynamic values in BPMN field labels +The embedded form in the camunda task does not support dynamic values by default. +In the workflow model is a "method _evaluate_form_field_label" that will parse a form label with the following structure {{workflow.prop}} +`` + + + +`` +The above label will be parsed to "This is a sentence for case 123" +Currently all properties and related objects of the workflow model are supported diff --git a/app/apps/workflow/bpmn_files/default/process_vve_ok/1.4.0/process_vve_ok.bpmn b/app/apps/workflow/bpmn_files/default/process_vve_ok/1.4.0/process_vve_ok.bpmn index 21d9481..09159b9 100644 --- a/app/apps/workflow/bpmn_files/default/process_vve_ok/1.4.0/process_vve_ok.bpmn +++ b/app/apps/workflow/bpmn_files/default/process_vve_ok/1.4.0/process_vve_ok.bpmn @@ -354,7 +354,7 @@ - + diff --git a/app/apps/workflow/models.py b/app/apps/workflow/models.py index 9556228..dcff0f1 100644 --- a/app/apps/workflow/models.py +++ b/app/apps/workflow/models.py @@ -23,7 +23,7 @@ task_script_wait, task_start_subworkflow, ) -from .utils import get_initial_data_from_config, parse_task_spec_form +from .utils import get_initial_data_from_config class CaseWorkflow(models.Model): @@ -161,7 +161,7 @@ def _create_user_tasks(self, wf): task_name=task.task_spec.name, name=task.task_spec.bpmn_name, roles=[r.strip() for r in task.task_spec.lane.split(",")], - form=parse_task_spec_form(task.task_spec.form), + form=self._parse_task_spec_form(task.task_spec.form), due_date=datetime.datetime.today(), case=self.case, workflow=self, @@ -175,6 +175,45 @@ def _create_user_tasks(self, wf): task_instances = CaseUserTask.objects.bulk_create(task_data) return task_instances + def _evaluate_form_field_label(self, label): + expression = label.replace("{{", "{").replace("}}", "}") + return expression.format(workflow=self) + + def _parse_task_spec_form(self, form): + trans_types = { + "enum": "select", + "boolean": "checkbox", + "string": "text", + "long": "number", + "expression": "expression", + } + fields = [ + { + "label": self._evaluate_form_field_label(f.label), + "options": [ + { + "value": o.id, + "label": o.name, + } + for o in f.__dict__.get("options", []) + ], + "name": f.id, + "type": ( + "multiselect" + if bool([v.name for v in f.validation if v.name == "multiple"]) + else trans_types.get(f.type, "text") + ), + "required": not bool( + [v.name for v in f.validation if v.name == "optional"] + ), + "tooltip": next( + iter([v.value for v in f.properties if v.id == "tooltip"]), None + ), + } + for f in form.fields + ] + return fields + def _set_obsolete_tasks_to_completed(self, wf): ready_tasks_ids = [t.id for t in wf.get_tasks(state=TaskState.READY)] task_instances = self.tasks.all().exclude( diff --git a/app/apps/workflow/utils.py b/app/apps/workflow/utils.py index f81ade4..3478cbf 100644 --- a/app/apps/workflow/utils.py +++ b/app/apps/workflow/utils.py @@ -172,41 +172,6 @@ def validate_workflow_spec(workflow_spec_config): return serializer.data -def parse_task_spec_form(form): - trans_types = { - "enum": "select", - "boolean": "checkbox", - "string": "text", - "long": "number", - } - fields = [ - { - "label": f.label, - "options": [ - { - "value": o.id, - "label": o.name, - } - for o in f.__dict__.get("options", []) - ], - "name": f.id, - "type": ( - "multiselect" - if bool([v.name for v in f.validation if v.name == "multiple"]) - else trans_types.get(f.type, "text") - ), - "required": not bool( - [v.name for v in f.validation if v.name == "optional"] - ), - "tooltip": next( - iter([v.value for v in f.properties if v.id == "tooltip"]), None - ), - } - for f in form.fields - ] - return fields - - def get_latest_version_from_config(workflow_type): validated_workflow_spec_config = validate_workflow_spec( settings.WORKFLOW_SPEC_CONFIG diff --git a/app/config/settings.py b/app/config/settings.py index a5d2e97..1c7b930 100644 --- a/app/config/settings.py +++ b/app/config/settings.py @@ -116,7 +116,6 @@ "https://login.microsoftonline.com/72fca1b1-2c2e-4376-a445-294d80196804/discovery/v2.0/keys", ) OIDC_RP_CLIENT_SECRET = os.environ.get("OIDC_RP_CLIENT_SECRET", None) - ROOT_URLCONF = "config.urls" TEMPLATES = [