forms: publish workflow role info in substitution variables (#5945)

This commit is contained in:
Frédéric Péters 2014-11-20 16:12:13 +01:00
parent 16cff31f82
commit 8fcee2f876
3 changed files with 32 additions and 0 deletions

View File

@ -200,6 +200,14 @@ champs, etc.
<td><p><code>form_evolution</code></p></td>
<td><p>L'ensemble de l'historique du traitement</p></td>
</tr>
<tr>
<td><p><code>form_role_receiver_name</code></p></td>
<td><p>Le nom du rôle en charge du traitement</p></td>
</tr>
<tr>
<td><p><code>form_role_receiver_emails</code></p></td>
<td><p>Les adresses électroniques associées au rôle en charge du traitement</p></td>
</tr>
</table>
</section>

View File

@ -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:

View File

@ -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'