Add possibility to be notified of submitted forms
This commit is contained in:
parent
c4bea77f51
commit
62a0439c17
|
@ -213,15 +213,47 @@ class RootDirectory(AccessControlled, Directory):
|
|||
def create_asec_objects(self):
|
||||
if not workflows.Workflow.has_key('asec-default'):
|
||||
workflow = workflows.Workflow(name=_('Default Workflow'))
|
||||
workflow._version = 1
|
||||
workflow.id = 'asec-default'
|
||||
workflow.add_status(_('Done'))
|
||||
status = workflow.add_status(_('Done'))
|
||||
status.id = 'done'
|
||||
workflow.store()
|
||||
|
||||
if not workflows.Workflow.has_key('asec-default+anonymous'):
|
||||
import anonymity
|
||||
workflow = workflows.Workflow(name=_('Default Workflow, Anonymous'))
|
||||
workflow._version = 1
|
||||
workflow.id = 'asec-default+anonymous'
|
||||
status = workflow.add_status(_('Done'))
|
||||
status.items = [anonymity.AnonymiseStatusItem()]
|
||||
status.id = 'done'
|
||||
workflow.store()
|
||||
|
||||
wf1 = workflows.Workflow.get('asec-default')
|
||||
wf2 = workflows.Workflow.get('asec-default+anonymous')
|
||||
|
||||
# fix workflows created in the first versions of asec, to have them
|
||||
# versioned like new ones.
|
||||
if not hasattr(wf1, 'version'):
|
||||
wf1.version = 1
|
||||
wf1.possible_status[0].id = 'done'
|
||||
if not hasattr(wf2, 'version'):
|
||||
wf2.version = 1
|
||||
wf2.possible_status[0].id = 'done'
|
||||
|
||||
for wf in (wf1, wf2):
|
||||
if wf.version < 2:
|
||||
# add a Sendmail action, left blank
|
||||
wf.version = 2
|
||||
status = wf.get_status('done')
|
||||
sendmail_item = workflows.SendmailWorkflowStatusItem()
|
||||
sendmail_item.id = 'mail-on-filled'
|
||||
sendmail_item.subject = _('New questionnaire ([name]) has been filled')
|
||||
sendmail_item.body = _('''\
|
||||
A new questionnaire ([name]) has been filled.
|
||||
|
||||
[details]
|
||||
''')
|
||||
status.items.append(sendmail_item)
|
||||
wf.store()
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ class DiffusionDirectory(Directory):
|
|||
('access-disabled', 'access_disabled'),
|
||||
('access-public', 'access_public'),
|
||||
('access-private', 'access_private'),
|
||||
'enable', 'disable', 'emailfrom']
|
||||
'enable', 'disable', 'emailfrom', 'emailnotify']
|
||||
|
||||
def __init__(self, objectdef):
|
||||
self.objectdef = objectdef
|
||||
|
@ -228,6 +228,38 @@ class DiffusionDirectory(Directory):
|
|||
cfg_submit(form, 'emails', ['from'])
|
||||
redirect('.')
|
||||
|
||||
def emailnotify [html] (self):
|
||||
emails_cfg = get_cfg('emails', {})
|
||||
form = Form(enctype='multipart/form-data')
|
||||
|
||||
if not self.objectdef.workflow_options:
|
||||
self.objectdef.workflow_options = {}
|
||||
form.add(EmailWidget, 'notify', title=_('Address for notifications'),
|
||||
value=self.objectdef.workflow_options.get('done*mail-on-filled*to'),
|
||||
hint=_('Leave blank to disable notifications'),
|
||||
size=30)
|
||||
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
if form.get_widget('cancel').parse():
|
||||
return redirect('.')
|
||||
|
||||
if not form.is_submitted() or form.has_errors():
|
||||
get_response().breadcrumb.append( ('emailfrom', _('Sender Address')) )
|
||||
html_top('config', title = _('Sender Address'))
|
||||
'<h2>%s</h2>' % _('Sender Address')
|
||||
form.render()
|
||||
else:
|
||||
v = form.get_widget('notify').parse()
|
||||
if v:
|
||||
v = str(v)
|
||||
else:
|
||||
v = None
|
||||
self.objectdef.workflow_options[str('done*mail-on-filled*to')] = v
|
||||
self.objectdef.store()
|
||||
redirect('.')
|
||||
|
||||
|
||||
def set_role(self):
|
||||
try:
|
||||
role = Role.get('participants-for-%s' % self.objectdef.id)
|
||||
|
@ -291,6 +323,17 @@ class DiffusionDirectory(Directory):
|
|||
' (<a href="emailfrom" rel="popup">%s</a>)' % _('set address')
|
||||
'</li>'
|
||||
|
||||
'<li>%s' % _('Notification when a questionnaire is filled: ')
|
||||
if not self.objectdef.workflow_options:
|
||||
self.objectdef.workflow_options = {}
|
||||
if self.objectdef.workflow_options.get('done*mail-on-filled*to'):
|
||||
self.objectdef.workflow_options.get('done*mail-on-filled*to')
|
||||
' (<a href="emailnotify" rel="popup">%s</a>)' % _('change address')
|
||||
else:
|
||||
_('None set')
|
||||
' (<a href="emailnotify" rel="popup">%s</a>)' % _('set address')
|
||||
'</li>'
|
||||
|
||||
'</ul>'
|
||||
|
||||
get_response().filter['sidebar'] = self.get_sidebar()
|
||||
|
|
Reference in New Issue