work in progress: rule handling
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2149 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									81b8564278
								
							
						
					
					
						commit
						39ffba3b03
					
				
					 8 changed files with 51 additions and 22 deletions
				
			
		|  | @ -39,13 +39,16 @@ class MessageManager(object): | ||||||
|     messages = None |     messages = None | ||||||
|     manager = None |     manager = None | ||||||
| 
 | 
 | ||||||
|     def __init__(self): |  | ||||||
|         if self.messagesFactory is not None: |  | ||||||
|             self.messages = self.messagesFactory() |  | ||||||
| 
 |  | ||||||
|     def getManager(self): |     def getManager(self): | ||||||
|         return self.manager |         return self.manager | ||||||
| 
 | 
 | ||||||
|  |     def addMessage(self, messageName, text): | ||||||
|  |         message = Message(messageName, manager=self) | ||||||
|  |         message.text = text | ||||||
|  |         if self.messages is None: | ||||||
|  |             self.messages = self.messagesFactory() | ||||||
|  |         self.messages.append(message) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class Message(Template): | class Message(Template): | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,6 +25,7 @@ $Id$ | ||||||
| from string import Template | from string import Template | ||||||
| from zope import component | from zope import component | ||||||
| from zope.interface import implements | from zope.interface import implements | ||||||
|  | from zope.publisher.browser import TestRequest | ||||||
| 
 | 
 | ||||||
| from cybertools.composer.instance import Instance | from cybertools.composer.instance import Instance | ||||||
| from cybertools.composer.interfaces import IInstance | from cybertools.composer.interfaces import IInstance | ||||||
|  | @ -38,7 +39,7 @@ class MessageInstance(Instance): | ||||||
|         self.client = client |         self.client = client | ||||||
|         self.template = template |         self.template = template | ||||||
| 
 | 
 | ||||||
|     def applyTemplate(self, **kw): |     def applyTemplate(self, data=None, **kw): | ||||||
|         data = DataProvider(self) |         data = DataProvider(self) | ||||||
|         return MessageTemplate(self.template.text).safe_substitute(data) |         return MessageTemplate(self.template.text).safe_substitute(data) | ||||||
| 
 | 
 | ||||||
|  | @ -55,9 +56,12 @@ class DataProvider(object): | ||||||
|             viewName = key[2:] |             viewName = key[2:] | ||||||
|             if client is None: |             if client is None: | ||||||
|                 return '$' + key |                 return '$' + key | ||||||
|             view = component.getMultiAdapter( |             view = component.queryMultiAdapter( | ||||||
|                     (client.manager, TestRequest(form=form)), name=viewName) |                     (client.manager, TestRequest()), name=viewName) | ||||||
|             return view() |             if view is not None: | ||||||
|  |                 return view() | ||||||
|  |             else: | ||||||
|  |                 return key | ||||||
|         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) | ||||||
|  |  | ||||||
|  | @ -42,6 +42,10 @@ class IMessageManager(Interface): | ||||||
| 
 | 
 | ||||||
|     messages = Attribute('A collection of message objects managed.') |     messages = Attribute('A collection of message objects managed.') | ||||||
| 
 | 
 | ||||||
|  |     def addMessage(name, text): | ||||||
|  |         """ Add a message under the name given with the given message text. | ||||||
|  |         """ | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class IMessage(ITemplate): | class IMessage(ITemplate): | ||||||
|     """ A complex message that may be expanded using instance data. |     """ A complex message that may be expanded using instance data. | ||||||
|  |  | ||||||
|  | @ -63,15 +63,6 @@ class RuleManager(object): | ||||||
|             ri.template = r |             ri.template = r | ||||||
|             ri.event = event |             ri.event = event | ||||||
|             ri.applyTemplate() |             ri.applyTemplate() | ||||||
|             #for c in r.conditions: |  | ||||||
|             #    cond = component.getAdapter(r, ICondition, name=c) |  | ||||||
|             #    if not cond(event): |  | ||||||
|             #        continue |  | ||||||
|             #data = None |  | ||||||
|             #for action in r.actions: |  | ||||||
|             #    handler = component.getAdapter(action, IActionHandler, |  | ||||||
|             #                                   name=action.handlerName) |  | ||||||
|             #    data = handler(data, event) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Rule(Template): | class Rule(Template): | ||||||
|  | @ -166,5 +157,5 @@ class ActionHandler(object): | ||||||
|     def __init__(self, context): |     def __init__(self, context): | ||||||
|         self.context = context |         self.context = context | ||||||
| 
 | 
 | ||||||
|     def __call__(self, data, event, params={}): |     def __call__(self, data, params={}): | ||||||
|         pass |         pass | ||||||
|  |  | ||||||
|  | @ -42,9 +42,9 @@ class RuleInstance(Instance): | ||||||
|             cond = component.getAdapter(self, ICondition, name=c) |             cond = component.getAdapter(self, ICondition, name=c) | ||||||
|             if not cond(): |             if not cond(): | ||||||
|                 continue |                 continue | ||||||
|         data = None |         data = {} | ||||||
|         for action in self.template.actions: |         for action in self.template.actions: | ||||||
|             handler = component.getAdapter(self, IActionHandler, |             handler = component.getAdapter(self, IActionHandler, | ||||||
|                                            name=action.handlerName) |                                            name=action.handlerName) | ||||||
|             data = handler(data, self.event) |             data = handler(data, action.parameters) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -17,7 +17,7 @@ | ||||||
| # | # | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| Event definitions. | Action handler for sending emails. | ||||||
| 
 | 
 | ||||||
| $Id$ | $Id$ | ||||||
| """ | """ | ||||||
|  |  | ||||||
|  | @ -3,6 +3,14 @@ | ||||||
| import unittest, doctest | import unittest, doctest | ||||||
| from zope.testing.doctestunit import DocFileSuite | from zope.testing.doctestunit import DocFileSuite | ||||||
| 
 | 
 | ||||||
|  | from cybertools.composer.rule.base import ActionHandler | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class MailActionHandler(ActionHandler): | ||||||
|  | 
 | ||||||
|  |     def __call__(self, data, event, params={}): | ||||||
|  |         pass | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class Test(unittest.TestCase): | class Test(unittest.TestCase): | ||||||
|     "Basic tests." |     "Basic tests." | ||||||
|  |  | ||||||
|  | @ -31,6 +31,7 @@ from zope import component | ||||||
| from zope.interface import implements, Interface | from zope.interface import implements, Interface | ||||||
| 
 | 
 | ||||||
| from cybertools.composer.interfaces import IInstance | from cybertools.composer.interfaces import IInstance | ||||||
|  | from cybertools.composer.message.base import MessageManager | ||||||
| from cybertools.composer.rule.base import RuleManager, EventType | from cybertools.composer.rule.base import RuleManager, EventType | ||||||
| from cybertools.composer.schema.interfaces import IClientManager, IClient | from cybertools.composer.schema.interfaces import IClientManager, IClient | ||||||
| from cybertools.stateful.base import StatefulAdapter | from cybertools.stateful.base import StatefulAdapter | ||||||
|  | @ -56,6 +57,8 @@ class ServiceManager(object): | ||||||
|     services = None |     services = None | ||||||
|     clients = None |     clients = None | ||||||
| 
 | 
 | ||||||
|  |     messages = None | ||||||
|  | 
 | ||||||
|     allowRegWithNumber = False |     allowRegWithNumber = False | ||||||
|     allowDirectRegistration = True |     allowDirectRegistration = True | ||||||
| 
 | 
 | ||||||
|  | @ -344,7 +347,7 @@ class StatefulRegistration(StatefulAdapter): | ||||||
|     statesDefinition = registrationStates |     statesDefinition = registrationStates | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # rules and events | # events, rules, actions | ||||||
| 
 | 
 | ||||||
| eventTypes = Jeep(( | eventTypes = Jeep(( | ||||||
|     EventType('service.checkout'), |     EventType('service.checkout'), | ||||||
|  | @ -359,6 +362,22 @@ class RuleManagerAdapter(RuleManager): | ||||||
|         self.context = context |         self.context = context | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class MessageManagerAdapter(MessageManager): | ||||||
|  | 
 | ||||||
|  |     adapts(IServiceManager) | ||||||
|  | 
 | ||||||
|  |     def __init__(self, context): | ||||||
|  |         self.context = context | ||||||
|  | 
 | ||||||
|  |     def addMessage(self, messageName, text): | ||||||
|  |         super(MessageManagerAdapter, self).addMessage(messageName, text) | ||||||
|  |         self.context.messages = self.messages | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def messages(self): | ||||||
|  |         return self.context.messages | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| # Zope event handlers | # Zope event handlers | ||||||
| 
 | 
 | ||||||
| def clientRemoved(obj, event): | def clientRemoved(obj, event): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm