Sending feedback message via rule manager OK
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2171 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
800e09e830
commit
be088b1f63
7 changed files with 22 additions and 23 deletions
|
@ -40,10 +40,10 @@ Working with message instances
|
|||
------------------------------
|
||||
|
||||
>>> from cybertools.composer.message.instance import MessageInstance
|
||||
>>> mi = MessageInstance(None, manager.messages['feedback_text'])
|
||||
>>> mi = MessageInstance(None, manager.messages['feedback_text'], manager)
|
||||
>>> for key, value in mi.applyTemplate().items():
|
||||
... print key + ':', value
|
||||
subject:
|
||||
subjectLine:
|
||||
text: Dear $person.firstname $person.lastname,
|
||||
You have been registered for the following events.
|
||||
$@@list_registrations
|
||||
|
|
|
@ -57,10 +57,10 @@ class Message(Template):
|
|||
name = u''
|
||||
manager = None
|
||||
|
||||
def __init__(self, name, text=u'', subject=u'', **kw):
|
||||
def __init__(self, name, text=u'', subjectLine=u'', **kw):
|
||||
self.name = name
|
||||
self.text = text
|
||||
self.subject = subject
|
||||
self.subjectLine = subjectLine
|
||||
for k, v in kw.items():
|
||||
setattr(self, k, v)
|
||||
|
||||
|
|
|
@ -36,15 +36,16 @@ class MessageInstance(Instance):
|
|||
|
||||
template = client = None
|
||||
|
||||
def __init__(self, client, template):
|
||||
def __init__(self, client, template, manager):
|
||||
self.client = client
|
||||
self.template = template
|
||||
self.manager = manager
|
||||
|
||||
def applyTemplate(self, data=None, **kw):
|
||||
data = DataProvider(self)
|
||||
text = MessageTemplate(self.template.text).safe_substitute(data)
|
||||
subject = self.template.subject
|
||||
return Jeep((('subject', subject), ('text', text)))
|
||||
subject = self.template.subjectLine
|
||||
return Jeep((('subjectLine', subject), ('text', text)))
|
||||
|
||||
|
||||
class DataProvider(object):
|
||||
|
@ -54,7 +55,8 @@ class DataProvider(object):
|
|||
|
||||
def __getitem__(self, key):
|
||||
client = self.context.client
|
||||
messageManager = self.context.template.manager
|
||||
#messageManager = self.context.template.getManager()
|
||||
messageManager = self.context.manager
|
||||
if key.startswith('@@'):
|
||||
viewName = key[2:]
|
||||
if client is None:
|
||||
|
@ -68,13 +70,14 @@ class DataProvider(object):
|
|||
elif key in messageManager.messages:
|
||||
#mi = component.getMultiAdapter(
|
||||
# (client, messageManager.messages[key]), IInstance)
|
||||
mi = MessageInstance(client, messageManager.messages[key])
|
||||
mi = MessageInstance(client, messageManager.messages[key],
|
||||
messageManager)
|
||||
return mi.applyTemplate().text
|
||||
elif '.' in key:
|
||||
if client is None:
|
||||
return '$' + key
|
||||
schemaName, fieldName = key.split('.', 1)
|
||||
schema = client.manager.clientSchemas[schemaName]
|
||||
schema = client.manager.getClientSchemas()[schemaName]
|
||||
instance = IInstance(client)
|
||||
instance.template = schema
|
||||
data = instance.applyTemplate()
|
||||
|
|
|
@ -63,7 +63,7 @@ class IMessage(ITemplate):
|
|||
title=_(u'Description'),
|
||||
description=_(u'A brief description of the message.'),
|
||||
required=False,)
|
||||
subject = schema.TextLine(
|
||||
subjectLine = schema.TextLine(
|
||||
title=_(u'Subject'),
|
||||
description=_(u'A short text that may be used as the subject '
|
||||
'line for emails or as a page title for web pages.'),
|
||||
|
|
|
@ -25,7 +25,6 @@ $Id$
|
|||
from email.MIMEText import MIMEText
|
||||
from zope import component
|
||||
from zope.interface import implements
|
||||
from zope.sendmail.interfaces import IMailDelivery
|
||||
|
||||
from cybertools.composer.interfaces import IInstance
|
||||
from cybertools.composer.rule.base import ActionHandler
|
||||
|
@ -34,15 +33,11 @@ from cybertools.composer.rule.base import ActionHandler
|
|||
class MailActionHandler(ActionHandler):
|
||||
|
||||
def __call__(self, data, params={}):
|
||||
#print 'sending mail...'
|
||||
#print 'subject:', data.subject
|
||||
#print 'text:', data.text
|
||||
#print 'params:', params
|
||||
sender = params.get('sender', 'unknown')
|
||||
client = self.context.context
|
||||
clientData = IInstance(client).applyTemplate()
|
||||
recipient = clientData['standard.email']
|
||||
msg = self.prepareMessage(data.subject, data.text, sender, recipient)
|
||||
msg = self.prepareMessage(data.subjectLine, data.text, sender, recipient)
|
||||
data['mailInfo'] = self.sendMail(msg.as_string(), sender, [recipient])
|
||||
return data
|
||||
|
||||
|
@ -55,6 +50,7 @@ class MailActionHandler(ActionHandler):
|
|||
return msg
|
||||
|
||||
def sendMail(self, message, sender, recipients):
|
||||
from zope.sendmail.interfaces import IMailDelivery
|
||||
mailhost = component.getUtility(IMailDelivery, 'Mail')
|
||||
mailhost.send(sender, recipients, message)
|
||||
return 'Mail sent to %s.' % ', '.join(recipients)
|
||||
|
|
|
@ -42,6 +42,6 @@ class MessageActionHandler(ActionHandler):
|
|||
if message is None:
|
||||
raise ValueError('Message %s does not exist.' % messageName)
|
||||
#client = IClient(self.context)
|
||||
mi = MessageInstance(client, message)
|
||||
mi = MessageInstance(client, message, manager)
|
||||
#mi.template = message
|
||||
return mi.applyTemplate(data)
|
||||
|
|
|
@ -164,6 +164,11 @@ class IServiceManager(Interface):
|
|||
'with the service description; otherwise registration '
|
||||
'is only possible on a registration template.'),
|
||||
required=False,)
|
||||
senderEmail = schema.TextLine(
|
||||
title=_(u'Sender email'),
|
||||
description=_(u'Email address that will be used as sender '
|
||||
'address of confirmation and feedback messages.'),
|
||||
required=False,)
|
||||
|
||||
services = Attribute('A collection of services managed by this object.')
|
||||
|
||||
|
@ -256,11 +261,6 @@ class IService(Interface):
|
|||
description=_(u'Web address (URL) for more information '
|
||||
'about the service.'),
|
||||
required=False,)
|
||||
senderEmail = schema.TextLine(
|
||||
title=_(u'Sender email'),
|
||||
description=_(u'Email address that will be used as sender '
|
||||
'address of confirmation and feedback messages.'),
|
||||
required=False,)
|
||||
|
||||
availableCapacity = Attribute('Available capacity, i.e. number of seats '
|
||||
'still available; a negative number means: '
|
||||
|
|
Loading…
Add table
Reference in a new issue