From 15a1f19f90d57adc7750293af0046a72369d41d4 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Tue, 26 Sep 2017 17:13:47 +0200 Subject: [PATCH] mail with attachments, draft #8274 --- wcs/workflows.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/wcs/workflows.py b/wcs/workflows.py index 06dffcdf..9c749ddb 100644 --- a/wcs/workflows.py +++ b/wcs/workflows.py @@ -2049,6 +2049,7 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem): subject = None body = None custom_from = None + attachments = None comment = None @@ -2087,7 +2088,7 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem): return _('Send mail (not completed)') def get_parameters(self): - return ('to', 'subject', 'body', 'custom_from') + return ('to', 'subject', 'body', 'attachments', 'custom_from') def fill_admin_form(self, form): self.add_parameters_widgets(form, self.get_parameters()) @@ -2110,6 +2111,38 @@ class SendmailWorkflowStatusItem(WorkflowStatusItem): value=self.body, cols=80, rows=10, validation_function=ComputedExpressionWidget.validate_ezt, hint=_('Available variables: url, url_status, details, name, number, comment, field_NAME')) + + attachments_fields = [(None, '---', None)] + attachments_bofields = [] + for field in self.parent.parent.get_backoffice_fields(): + if field.key != 'file': + continue + if field.varname: + codename = 'form_var_%s' % field.varname + else: + codename = '__f%s' % field.id # __fbo + attachments_bofields.append(codename) + attachments_fields.append((codename, field.label, codename)) + # don't show removed backoffice fields without varnames + attachments = [attachment for attachment in self.attachments or [] + if ((not attachment.startswith('__f')) or (attachment in attachments_bofields))] + if 'attachments' in parameters: + if len(attachments_fields) > 1: + form.add(WidgetList, '%sattachments' % prefix, title=_('Attachments'), + element_type=SingleSelectWidgetWithOther, + value=attachments, + add_element_label=_('Add attachment'), + element_kwargs={'render_br': False, 'options': attachments_fields, + 'other_label': _('Other (Python expression):')}) + else: + form.add(WidgetList, '%sattachments' % prefix, + title=_('Attachments (Python expressions)'), + element_type=StringWidget, + value=attachments, + add_element_label=_('Add attachment'), + element_kwargs={'render_br': False, 'size': 50}, + advanced=not(bool(self.attachments))) + if 'custom_from' in parameters: form.add(ComputedExpressionWidget, '%scustom_from' % prefix, title=_('Custom From Address'), value=self.custom_from, -- 2.14.1