From 8fcee2f876677de6026839dc5113b0f76841e280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 20 Nov 2014 16:12:13 +0100 Subject: [PATCH] forms: publish workflow role info in substitution variables (#5945) --- help/fr/misc-substvars.page | 8 ++++++++ wcs/formdata.py | 16 ++++++++++++++++ wcs/roles.py | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/help/fr/misc-substvars.page b/help/fr/misc-substvars.page index f39b48466..a9d7e848f 100644 --- a/help/fr/misc-substvars.page +++ b/help/fr/misc-substvars.page @@ -200,6 +200,14 @@ champs, etc.

form_evolution

L'ensemble de l'historique du traitement

+ +

form_role_receiver_name

+

Le nom du rôle en charge du traitement

+ + +

form_role_receiver_emails

+

Les adresses électroniques associées au rôle en charge du traitement

+ diff --git a/wcs/formdata.py b/wcs/formdata.py index 2ec038936..ed85a7b8d 100644 --- a/wcs/formdata.py +++ b/wcs/formdata.py @@ -25,6 +25,8 @@ from qommon.storage import StorableObject import qommon.misc from qommon.substitution import Substitutions +from roles import Role + def get_dict_with_varnames(fields, data): new_data = {} @@ -358,6 +360,20 @@ class FormData(StorableObject): for k, v in self.get_as_dict().items(): d['form_'+k] = v + # include substitution variables for workflow roles; this will + # typically give variables such as form_role_receiver_name and + # form_role_receiver_emails. + workflow_roles = self.formdef.workflow_roles.copy() + if self.workflow_roles: + workflow_roles.update(self.workflow_roles) + + for role_type, role_id in workflow_roles.items(): + prefix = 'form_role_%s_' % role_type.strip('_') + try: + d.update(Role.get(role_id).get_substitution_variables(prefix)) + except KeyError: + pass + if self.evolution and self.evolution[-1].comment: d['form_comment'] = self.evolution[-1].comment else: diff --git a/wcs/roles.py b/wcs/roles.py index 32e7fd578..98a6379ac 100644 --- a/wcs/roles.py +++ b/wcs/roles.py @@ -39,6 +39,14 @@ class Role(StorableObject): emails.extend([x.email for x in users_with_roles if x.email]) return emails + def get_substitution_variables(self, prefix=''): + data = {} + data[prefix + 'name'] = self.name + if self.emails and not self.emails_to_members: + data[prefix + 'emails'] = ', '.join(self.emails) + return data + + def logged_users_role(): volatile_role = Role.volatile() volatile_role.id = 'logged-users'