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 |   >>> 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(): |   >>> for key, value in mi.applyTemplate().items(): | ||||||
|   ...     print key + ':', value |   ...     print key + ':', value | ||||||
|   subject: |   subjectLine: | ||||||
|   text: Dear $person.firstname $person.lastname, |   text: Dear $person.firstname $person.lastname, | ||||||
|   You have been registered for the following events. |   You have been registered for the following events. | ||||||
|   $@@list_registrations |   $@@list_registrations | ||||||
|  |  | ||||||
|  | @ -57,10 +57,10 @@ class Message(Template): | ||||||
|     name = u'' |     name = u'' | ||||||
|     manager = None |     manager = None | ||||||
| 
 | 
 | ||||||
|     def __init__(self, name, text=u'', subject=u'', **kw): |     def __init__(self, name, text=u'', subjectLine=u'', **kw): | ||||||
|         self.name = name |         self.name = name | ||||||
|         self.text = text |         self.text = text | ||||||
|         self.subject = subject |         self.subjectLine = subjectLine | ||||||
|         for k, v in kw.items(): |         for k, v in kw.items(): | ||||||
|             setattr(self, k, v) |             setattr(self, k, v) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -36,15 +36,16 @@ class MessageInstance(Instance): | ||||||
| 
 | 
 | ||||||
|     template = client = None |     template = client = None | ||||||
| 
 | 
 | ||||||
|     def __init__(self, client, template): |     def __init__(self, client, template, manager): | ||||||
|         self.client = client |         self.client = client | ||||||
|         self.template = template |         self.template = template | ||||||
|  |         self.manager = manager | ||||||
| 
 | 
 | ||||||
|     def applyTemplate(self, data=None, **kw): |     def applyTemplate(self, data=None, **kw): | ||||||
|         data = DataProvider(self) |         data = DataProvider(self) | ||||||
|         text = MessageTemplate(self.template.text).safe_substitute(data) |         text = MessageTemplate(self.template.text).safe_substitute(data) | ||||||
|         subject = self.template.subject |         subject = self.template.subjectLine | ||||||
|         return Jeep((('subject', subject), ('text', text))) |         return Jeep((('subjectLine', subject), ('text', text))) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class DataProvider(object): | class DataProvider(object): | ||||||
|  | @ -54,7 +55,8 @@ class DataProvider(object): | ||||||
| 
 | 
 | ||||||
|     def __getitem__(self, key): |     def __getitem__(self, key): | ||||||
|         client = self.context.client |         client = self.context.client | ||||||
|         messageManager = self.context.template.manager |         #messageManager = self.context.template.getManager() | ||||||
|  |         messageManager = self.context.manager | ||||||
|         if key.startswith('@@'): |         if key.startswith('@@'): | ||||||
|             viewName = key[2:] |             viewName = key[2:] | ||||||
|             if client is None: |             if client is None: | ||||||
|  | @ -68,13 +70,14 @@ class DataProvider(object): | ||||||
|         elif key in messageManager.messages: |         elif key in messageManager.messages: | ||||||
|             #mi = component.getMultiAdapter( |             #mi = component.getMultiAdapter( | ||||||
|             #       (client, messageManager.messages[key]), IInstance) |             #       (client, messageManager.messages[key]), IInstance) | ||||||
|             mi = MessageInstance(client, messageManager.messages[key]) |             mi = MessageInstance(client, messageManager.messages[key], | ||||||
|  |                                  messageManager) | ||||||
|             return mi.applyTemplate().text |             return mi.applyTemplate().text | ||||||
|         elif '.' in key: |         elif '.' in key: | ||||||
|             if client is None: |             if client is None: | ||||||
|                 return '$' + key |                 return '$' + key | ||||||
|             schemaName, fieldName = key.split('.', 1) |             schemaName, fieldName = key.split('.', 1) | ||||||
|             schema = client.manager.clientSchemas[schemaName] |             schema = client.manager.getClientSchemas()[schemaName] | ||||||
|             instance = IInstance(client) |             instance = IInstance(client) | ||||||
|             instance.template = schema |             instance.template = schema | ||||||
|             data = instance.applyTemplate() |             data = instance.applyTemplate() | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ class IMessage(ITemplate): | ||||||
|                 title=_(u'Description'), |                 title=_(u'Description'), | ||||||
|                 description=_(u'A brief description of the message.'), |                 description=_(u'A brief description of the message.'), | ||||||
|                 required=False,) |                 required=False,) | ||||||
|     subject = schema.TextLine( |     subjectLine = schema.TextLine( | ||||||
|                 title=_(u'Subject'), |                 title=_(u'Subject'), | ||||||
|                 description=_(u'A short text that may be used as the subject ' |                 description=_(u'A short text that may be used as the subject ' | ||||||
|                         'line for emails or as a page title for web pages.'), |                         'line for emails or as a page title for web pages.'), | ||||||
|  |  | ||||||
|  | @ -25,7 +25,6 @@ $Id$ | ||||||
| from email.MIMEText import MIMEText | from email.MIMEText import MIMEText | ||||||
| from zope import component | from zope import component | ||||||
| from zope.interface import implements | from zope.interface import implements | ||||||
| from zope.sendmail.interfaces import IMailDelivery |  | ||||||
| 
 | 
 | ||||||
| from cybertools.composer.interfaces import IInstance | from cybertools.composer.interfaces import IInstance | ||||||
| from cybertools.composer.rule.base import ActionHandler | from cybertools.composer.rule.base import ActionHandler | ||||||
|  | @ -34,15 +33,11 @@ from cybertools.composer.rule.base import ActionHandler | ||||||
| class MailActionHandler(ActionHandler): | class MailActionHandler(ActionHandler): | ||||||
| 
 | 
 | ||||||
|     def __call__(self, data, params={}): |     def __call__(self, data, params={}): | ||||||
|         #print 'sending mail...' |  | ||||||
|         #print 'subject:', data.subject |  | ||||||
|         #print 'text:', data.text |  | ||||||
|         #print 'params:', params |  | ||||||
|         sender = params.get('sender', 'unknown') |         sender = params.get('sender', 'unknown') | ||||||
|         client = self.context.context |         client = self.context.context | ||||||
|         clientData = IInstance(client).applyTemplate() |         clientData = IInstance(client).applyTemplate() | ||||||
|         recipient = clientData['standard.email'] |         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]) |         data['mailInfo'] = self.sendMail(msg.as_string(), sender, [recipient]) | ||||||
|         return data |         return data | ||||||
| 
 | 
 | ||||||
|  | @ -55,6 +50,7 @@ class MailActionHandler(ActionHandler): | ||||||
|         return msg |         return msg | ||||||
| 
 | 
 | ||||||
|     def sendMail(self, message, sender, recipients): |     def sendMail(self, message, sender, recipients): | ||||||
|  |         from zope.sendmail.interfaces import IMailDelivery | ||||||
|         mailhost = component.getUtility(IMailDelivery, 'Mail') |         mailhost = component.getUtility(IMailDelivery, 'Mail') | ||||||
|         mailhost.send(sender, recipients, message) |         mailhost.send(sender, recipients, message) | ||||||
|         return 'Mail sent to %s.' % ', '.join(recipients) |         return 'Mail sent to %s.' % ', '.join(recipients) | ||||||
|  |  | ||||||
|  | @ -42,6 +42,6 @@ class MessageActionHandler(ActionHandler): | ||||||
|         if message is None: |         if message is None: | ||||||
|             raise ValueError('Message %s does not exist.' % messageName) |             raise ValueError('Message %s does not exist.' % messageName) | ||||||
|         #client = IClient(self.context) |         #client = IClient(self.context) | ||||||
|         mi = MessageInstance(client, message) |         mi = MessageInstance(client, message, manager) | ||||||
|         #mi.template = message |         #mi.template = message | ||||||
|         return mi.applyTemplate(data) |         return mi.applyTemplate(data) | ||||||
|  |  | ||||||
|  | @ -164,6 +164,11 @@ class IServiceManager(Interface): | ||||||
|                         'with the service description; otherwise registration ' |                         'with the service description; otherwise registration ' | ||||||
|                         'is only possible on a registration template.'), |                         'is only possible on a registration template.'), | ||||||
|                 required=False,) |                 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.') |     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 ' |                 description=_(u'Web address (URL) for more information ' | ||||||
|                         'about the service.'), |                         'about the service.'), | ||||||
|                 required=False,) |                 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 ' |     availableCapacity = Attribute('Available capacity, i.e. number of seats ' | ||||||
|                 'still available; a negative number means: ' |                 'still available; a negative number means: ' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm