eggification
[MosaicDocument.git] / Products / MosaicDocument / FileSlot.py
diff --git a/Products/MosaicDocument/FileSlot.py b/Products/MosaicDocument/FileSlot.py
new file mode 100755 (executable)
index 0000000..c4698b3
--- /dev/null
@@ -0,0 +1,85 @@
+# -*- coding: utf-8 -*-
+# (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
+# (c) 2003 BenoĆ®t PIN <mailto:pin@cri.ensmp.fr>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+#
+
+from OFS.SimpleItem import SimpleItem
+from OFS.PropertyManager import PropertyManager
+from OFS.Image import cookId
+from Globals import InitializeClass
+from Products.CMFCore.utils import getToolByName
+
+from Products.CMFCore.permissions import View, ModifyPortalContent
+from AccessControl import ClassSecurityInfo
+from Products.Plinn.File import File
+from BaseSlot import BaseSlot
+
+factory_type_information = ( {'id'             : 'File Slot',
+                              'meta_type'      : 'File Slot',
+                              'description'    : "File Slot for Mosaic Document",
+                              'icon'           : 'mosaic_tool/bin_icon.gif',
+                              'product'        : 'MosaicDocument',
+                              'factory'        : 'addFileSlot',
+                              'immediate_view' : 'view',
+                              'actions'        :
+                                ({'id'            : 'view',
+                                  'name'          : 'View',
+                                  'action'        : 'slot_file_view',
+                                  'permissions'   : (View, )
+                                  },
+                                 
+                                 {'id'            : 'edit',
+                                  'name'          : 'Edit',
+                                  'action'        : 'slot_file_form',
+                                  'permissions'   : (ModifyPortalContent, )
+                                  },
+                                 )
+                               },
+                             )
+
+class FileSlot(BaseSlot, File) :
+    """File Slot"""
+    meta_type = 'File Slot'
+    
+    filename = ''
+    _indexableFields = ('title',)
+
+    security = ClassSecurityInfo()
+
+    security.declareProtected(ModifyPortalContent, 'edit')
+    def edit(self, title='', file='') :
+        """ Edit file slot """
+        self.title = title
+        if file :
+            self._edit(file = file)
+            self.filename = cookId(None, None, file)[1]
+            
+            
+    security.declareProtected(View, 'SearchableText')
+    def SearchableText(self) :
+        """ Return full text for indexation """
+        return BaseSlot.SearchableText(self) + File.SearchableText(self)
+    
+
+InitializeClass(FileSlot)
+
+def addFileSlot(dispatcher, id, title='', file=''):
+    """
+    Add a new FileSlot object.
+    """
+    o = FileSlot(id, title=title, file=file)
+    dispatcher.Destination()._setObject(id, o)