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 | ||||
|     manager = None | ||||
| 
 | ||||
|     def __init__(self): | ||||
|         if self.messagesFactory is not None: | ||||
|             self.messages = self.messagesFactory() | ||||
| 
 | ||||
|     def getManager(self): | ||||
|         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): | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,6 +25,7 @@ $Id$ | |||
| from string import Template | ||||
| from zope import component | ||||
| from zope.interface import implements | ||||
| from zope.publisher.browser import TestRequest | ||||
| 
 | ||||
| from cybertools.composer.instance import Instance | ||||
| from cybertools.composer.interfaces import IInstance | ||||
|  | @ -38,7 +39,7 @@ class MessageInstance(Instance): | |||
|         self.client = client | ||||
|         self.template = template | ||||
| 
 | ||||
|     def applyTemplate(self, **kw): | ||||
|     def applyTemplate(self, data=None, **kw): | ||||
|         data = DataProvider(self) | ||||
|         return MessageTemplate(self.template.text).safe_substitute(data) | ||||
| 
 | ||||
|  | @ -55,9 +56,12 @@ class DataProvider(object): | |||
|             viewName = key[2:] | ||||
|             if client is None: | ||||
|                 return '$' + key | ||||
|             view = component.getMultiAdapter( | ||||
|                     (client.manager, TestRequest(form=form)), name=viewName) | ||||
|             view = component.queryMultiAdapter( | ||||
|                     (client.manager, TestRequest()), name=viewName) | ||||
|             if view is not None: | ||||
|                 return view() | ||||
|             else: | ||||
|                 return key | ||||
|         elif key in messageManager.messages: | ||||
|             #mi = component.getMultiAdapter( | ||||
|             #       (client, messageManager.messages[key]), IInstance) | ||||
|  |  | |||
|  | @ -42,6 +42,10 @@ class IMessageManager(Interface): | |||
| 
 | ||||
|     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): | ||||
|     """ A complex message that may be expanded using instance data. | ||||
|  |  | |||
|  | @ -63,15 +63,6 @@ class RuleManager(object): | |||
|             ri.template = r | ||||
|             ri.event = event | ||||
|             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): | ||||
|  | @ -166,5 +157,5 @@ class ActionHandler(object): | |||
|     def __init__(self, context): | ||||
|         self.context = context | ||||
| 
 | ||||
|     def __call__(self, data, event, params={}): | ||||
|     def __call__(self, data, params={}): | ||||
|         pass | ||||
|  |  | |||
|  | @ -42,9 +42,9 @@ class RuleInstance(Instance): | |||
|             cond = component.getAdapter(self, ICondition, name=c) | ||||
|             if not cond(): | ||||
|                 continue | ||||
|         data = None | ||||
|         data = {} | ||||
|         for action in self.template.actions: | ||||
|             handler = component.getAdapter(self, IActionHandler, | ||||
|                                            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$ | ||||
| """ | ||||
|  |  | |||
|  | @ -3,6 +3,14 @@ | |||
| import unittest, doctest | ||||
| 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): | ||||
|     "Basic tests." | ||||
|  |  | |||
|  | @ -31,6 +31,7 @@ from zope import component | |||
| from zope.interface import implements, Interface | ||||
| 
 | ||||
| from cybertools.composer.interfaces import IInstance | ||||
| from cybertools.composer.message.base import MessageManager | ||||
| from cybertools.composer.rule.base import RuleManager, EventType | ||||
| from cybertools.composer.schema.interfaces import IClientManager, IClient | ||||
| from cybertools.stateful.base import StatefulAdapter | ||||
|  | @ -56,6 +57,8 @@ class ServiceManager(object): | |||
|     services = None | ||||
|     clients = None | ||||
| 
 | ||||
|     messages = None | ||||
| 
 | ||||
|     allowRegWithNumber = False | ||||
|     allowDirectRegistration = True | ||||
| 
 | ||||
|  | @ -344,7 +347,7 @@ class StatefulRegistration(StatefulAdapter): | |||
|     statesDefinition = registrationStates | ||||
| 
 | ||||
| 
 | ||||
| # rules and events | ||||
| # events, rules, actions | ||||
| 
 | ||||
| eventTypes = Jeep(( | ||||
|     EventType('service.checkout'), | ||||
|  | @ -359,6 +362,22 @@ class RuleManagerAdapter(RuleManager): | |||
|         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 | ||||
| 
 | ||||
| def clientRemoved(obj, event): | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm