e9d19ea12adadd459359f51ed0db744db34d5a44
[MosaicDocument.git] / BaseSlot.py
1 # (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
2 # (c) 2003 BenoƮt PIN <mailto:pin@cri.ensmp.fr>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 # 02111-1307, USA.
17 #
18
19 from Globals import InitializeClass, DTMLFile
20 from Products.CMFCore.utils import getToolByName
21
22 from AccessControl import ClassSecurityInfo
23 from Products.CMFCore.permissions import View, ModifyPortalContent
24 from Products.CMFCore.DynamicType import DynamicType
25 from Products.PageTemplates.Expressions import getEngine
26 from Products.PageTemplates.Expressions import SecureModuleImporter
27
28 class BaseSlot(DynamicType) :
29 """Slot"""
30
31 _isMosaicSlot = 1
32 _editableFields = []
33 _indexableFields = []
34
35 security = ClassSecurityInfo()
36
37 security.declarePublic('callAction')
38 def callAction(self, actionId, *args, **kw) :
39 """call action from action definitions"""
40 typeTool = getToolByName(self, 'portal_types')
41
42 # !!! id et meta_type doivent etre identiques dans la fti.
43 typeInfo = typeTool.getTypeInfo(self)
44 actionInfo = typeInfo.getActionInfo('object/%s' % actionId)
45 zpt = getattr(self, actionInfo['url'])
46 return zpt(object=self, block=self.aq_parent, *args, **kw)
47
48 security.declareProtected(ModifyPortalContent, 'edit')
49 def edit(self, **kw) :
50 """ Edit Slot"""
51 for fieldName in self._editableFields :
52 if kw.has_key(fieldName) :
53 setattr(self, fieldName, kw[fieldName])
54
55 security.declareProtected(View, 'getBlock')
56 def getBlock(self) :
57 """ Return the block object where the slot is located """
58 return self.aq_parent
59
60 security.declareProtected(View, 'getExprContext')
61 def getExprContext(self, REQUEST=None) :
62 """Return an expression context customized for expressions properties from slot information"""
63 block = self.aq_parent
64 while block.meta_type != 'Mosaic Block' :
65 block = block.aq_parent
66 data = {
67 'portal' : self.portal_url.getPortalObject(),
68 'slot' : self,
69 'block' : self.aq_parent,
70 'here' : None,
71 'request' : REQUEST,
72 'modules' : SecureModuleImporter,
73 'nothing' : None,
74 }
75 return getEngine().getContext(data)
76
77 security.declareProtected(View, 'SearchableText')
78 def SearchableText(self) :
79 """ Return full text for indexation """
80 text = ''
81 for fieldName in self._indexableFields :
82 field = getattr(self, fieldName)
83 if callable(field) :
84 text += ' %s' % field()
85 else :
86 text += ' %s' % field
87
88 return text
89
90 def _initDefaultValues(self) :
91 pass
92
93 def indexObject(self): pass
94 def unindexObject(self): pass
95 def reindexObject(self, idxs=[]): pass
96 def reindexObjectSecurity(self): pass
97 def notifyWorkflowCreated(self): pass
98
99
100 InitializeClass(BaseSlot)