4b7c42eeb373e79bc048663e04d0421839d83990
[MosaicDocument.git] / FileSlot.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 OFS.SimpleItem import SimpleItem
20 from OFS.PropertyManager import PropertyManager
21 from OFS.Image import cookId
22 from Globals import InitializeClass
23 from Products.CMFCore.utils import getToolByName
24
25 from Products.CMFCore.permissions import View, ModifyPortalContent
26 from AccessControl import ClassSecurityInfo
27 from Products.Plinn.File import File
28 from BaseSlot import BaseSlot
29
30 factory_type_information = ( {'id' : 'File Slot',
31 'meta_type' : 'File Slot',
32 'description' : "File Slot for Mosaic Document",
33 'icon' : 'mosaic_tool/bin_icon.gif',
34 'product' : 'MosaicDocument',
35 'factory' : 'addFileSlot',
36 'immediate_view' : 'view',
37 'actions' :
38 ({'id' : 'view',
39 'name' : 'View',
40 'action' : 'slot_file_view',
41 'permissions' : (View, )
42 },
43
44 {'id' : 'edit',
45 'name' : 'Edit',
46 'action' : 'slot_file_form',
47 'permissions' : (ModifyPortalContent, )
48 },
49 )
50 },
51 )
52
53 class FileSlot(BaseSlot, File) :
54 """File Slot"""
55 meta_type = 'File Slot'
56
57 filename = ''
58 _indexableFields = ('title',)
59
60 security = ClassSecurityInfo()
61
62 security.declareProtected(ModifyPortalContent, 'edit')
63 def edit(self, title='', file='') :
64 """ Edit file slot """
65 self.title = title
66 if file :
67 self._edit(file = file)
68 self.filename = cookId(None, None, file)[1]
69
70
71 security.declareProtected(View, 'SearchableText')
72 def SearchableText(self) :
73 """ Return full text for indexation """
74 return BaseSlot.SearchableText(self) + File.SearchableText(self)
75
76
77 InitializeClass(FileSlot)
78
79 def addFileSlot(dispatcher, id, title='', file=''):
80 """
81 Add a new FileSlot object.
82 """
83 o = FileSlot(id, title=title, file=file)
84 dispatcher.Destination()._setObject(id, o)