Back to index

plone3  3.1.7
adding.py
Go to the documentation of this file.
00001 from warnings import warn
00002 
00003 from zope.interface import implements
00004 from zope.component import getMultiAdapter, getUtility
00005 from zope.app.container.interfaces import INameChooser
00006 
00007 from Acquisition import aq_base, aq_inner, aq_parent
00008 from OFS.SimpleItem import SimpleItem
00009 from Products.Five.browser import BrowserView
00010 
00011 from plone.contentrules.engine.interfaces import IRuleStorage
00012 
00013 from plone.app.contentrules.browser.interfaces import IRuleAdding
00014 from plone.app.contentrules.browser.interfaces import IRuleConditionAdding
00015 from plone.app.contentrules.browser.interfaces import IRuleActionAdding
00016 
00017 class RuleAdding(SimpleItem, BrowserView):
00018 
00019     implements(IRuleAdding)
00020 
00021     context = None
00022     request = None
00023     contentName = None
00024     
00025     # This is necessary so that context.absolute_url() works properly on the 
00026     # add form, which in turn fixes the <base /> URL
00027     id = '+rule'
00028 
00029     def __init__(self, context, request):
00030         self.context = context
00031         self.request = request
00032 
00033     def add(self, content):
00034         """Add the rule to the context
00035         """
00036         storage = getUtility(IRuleStorage)
00037         chooser = INameChooser(storage)
00038         storage[chooser.chooseName(None, content)] = content
00039 
00040     def nextURL(self):
00041         url = str(getMultiAdapter((self.context, self.request), name=u"absolute_url"))
00042         return url + "/@@rules-controlpanel"
00043 
00044     def renderAddButton(self):
00045         warn("The renderAddButton method is deprecated, use nameAllowed",
00046             DeprecationWarning, 2)
00047 
00048     def namesAccepted(self):
00049         return False
00050 
00051     def nameAllowed(self):
00052         return False
00053 
00054     def isSingleMenuItem(self):
00055         return False
00056 
00057     def addingInfo(self):
00058         return []
00059 
00060     def hasCustomAddView(self):
00061         return None
00062 
00063 
00064 class RuleElementAdding(SimpleItem, BrowserView):
00065 
00066     context = None
00067     request = None
00068     contentName = None
00069     
00070     def __init__(self, context, request):
00071         self.context = context
00072         self.request = request
00073 
00074     def nextURL(self):
00075         url = str(getMultiAdapter((aq_parent(self.context), self.request), name=u"absolute_url"))
00076         return url + "/@@manage-content-rules"
00077 
00078     def renderAddButton(self):
00079         warn("The renderAddButton method is deprecated, use nameAllowed",
00080             DeprecationWarning, 2)
00081 
00082     def namesAccepted(self):
00083         return False
00084 
00085     def nameAllowed(self):
00086         return False
00087 
00088     def isSingleMenuItem(self):
00089         return False
00090 
00091     def addingInfo(self):
00092         return []
00093 
00094     def hasCustomAddView(self):
00095         return None
00096 
00097 
00098 class RuleConditionAdding(RuleElementAdding):
00099 
00100     implements(IRuleConditionAdding)
00101     
00102     # This is necessary so that context.absolute_url() works properly on the 
00103     # add form, which in turn fixes the <base /> URL
00104     id = '+condition'
00105 
00106     def add(self, content):
00107         """Add the rule element to the context rule
00108         """
00109         rule = aq_base(aq_inner(self.context))
00110         rule.conditions.append(content)
00111 
00112 
00113 class RuleActionAdding(RuleElementAdding):
00114 
00115     implements(IRuleActionAdding)
00116     
00117     # This is necessary so that context.absolute_url() works properly on the 
00118     # add form, which in turn fixes the <base /> URL
00119     id = '+action'
00120 
00121     def add(self, content):
00122         """Add the rule element to the context rule
00123         """
00124         rule = aq_base(aq_inner(self.context))
00125         rule.actions.append(content)