Back to index

plone3  3.1.7
traversal.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.component import adapts, getUtility
00003 
00004 from zope.traversing.interfaces import ITraversable
00005 from zope.publisher.interfaces.browser import IBrowserRequest
00006 
00007 from plone.contentrules.engine.interfaces import IRuleStorage
00008 from plone.contentrules.rule.interfaces import IRule
00009 
00010 from Products.CMFCore.interfaces import ISiteRoot
00011 
00012 class RuleNamespace(object):
00013     """Used to traverse to a rule.
00014     
00015     Traversing to portal/++rule++foo will retrieve the rule with id 'foo'
00016     stored in context, acquisition-wrapped.
00017     """
00018     implements(ITraversable)
00019     adapts(ISiteRoot, IBrowserRequest)
00020     
00021     def __init__(self, context, request=None):
00022         self.context = context
00023         self.request = request
00024         
00025     def traverse(self, name, ignore):
00026         manager = getUtility(IRuleStorage)
00027         return manager[name]
00028 
00029 class RuleConditionNamespace(object):
00030     """Used to traverse to a rule condition
00031     
00032     Traversing to portal/++rule++foo/++condition++1 will retrieve the second
00033     condition of the rule rule with id 'foo', acquisition-wrapped.
00034     """
00035     implements(ITraversable)
00036     adapts(IRule, IBrowserRequest)
00037     
00038     def __init__(self, context, request=None):
00039         self.context = context
00040         self.request = request
00041         
00042     def traverse(self, name, ignore):
00043         condition = self.context.conditions[int(name)]
00044         traversal_id = "++condition++%s" % name
00045         if condition.id != traversal_id:
00046             condition.__name__ = condition.id = traversal_id
00047         return condition
00048         
00049 class RuleActionNamespace(object):
00050     """Used to traverse to a rule condition
00051     
00052     Traversing to portal/++rule++foo/++action++1 will retrieve the second
00053     condition of the rule rule with id 'foo', acquisition-wrapped.
00054     """
00055     implements(ITraversable)
00056     adapts(IRule, IBrowserRequest)
00057     
00058     def __init__(self, context, request=None):
00059         self.context = context
00060         self.request = request
00061         
00062     def traverse(self, name, ignore):
00063         action = self.context.actions[int(name)]
00064         traversal_id = "++action++%s" % name
00065         if action.id != traversal_id:
00066             action.__name__ = action.id = traversal_id
00067         return action