Back to index

plone3  3.1.7
__init__.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
00004 #
00005 # This software is distributed under the terms of the Kupu
00006 # License. See LICENSE.txt for license text. For a list of Kupu
00007 # Contributors see CREDITS.txt.
00008 #
00009 ##############################################################################
00010 """Zope2 integration module
00011 
00012 This is a solution for plain Zope2 integration using the
00013 FileSystemSite product. FileSystemSite can be found at
00014 http://www.zope.org/Members/k_vertigo/Products/FileSystemSite
00015 Note that FileSystemSite 1.3 is required.
00016 
00017 $Id: __init__.py 9879 2005-03-18 12:04:00Z yuppie $
00018 """
00019 
00020 import Globals
00021 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00022 
00023 from Products.FileSystemSite.DirectoryView import DirectoryView
00024 from Products.FileSystemSite.DirectoryView import DirectoryViewSurrogate
00025 from Products.FileSystemSite.DirectoryView import DirectoryRegistry
00026 from Products.FileSystemSite.DirectoryView import registerFileExtension
00027 from Products.FileSystemSite.DirectoryView import manage_listAvailableDirectories
00028 from Products.FileSystemSite.FSFile import FSFile
00029 
00030 def initialize(context):
00031     context.registerClass(
00032         KupuEditorSurrogate,
00033         constructors=(('manage_addKupuEditorForm', manage_addKupuEditorForm),
00034                       manage_addKupuEditor
00035                       ),
00036         icon='kupu_icon.gif'
00037     )
00038 
00039 #_dirreg = DirectoryRegistry()
00040 from Products.FileSystemSite.DirectoryView import _dirreg
00041 _dirreg.registerDirectory('../common', globals())
00042 
00043 # for library drawers
00044 registerFileExtension('xsl', FSFile)
00045 registerFileExtension('xml', FSFile)
00046 
00047 class KupuEditor(DirectoryView):
00048     meta_type = 'kupu editor'
00049 
00050     def __of__(self, parent):
00051         info = _dirreg.getDirectoryInfo(self._dirpath)
00052         if info is not None:
00053             info = info.getContents(_dirreg)
00054         if info is None:
00055             data = {}
00056             objects = ()
00057         else:
00058             data, objects = info
00059         s = KupuEditorSurrogate(self, data, objects)
00060         res = s.__of__(parent)
00061         return res
00062 
00063 Globals.InitializeClass(KupuEditor)
00064 
00065 class KupuEditorSurrogate(DirectoryViewSurrogate):
00066     meta_type = "kupu editor"
00067 
00068 Globals.InitializeClass(KupuEditorSurrogate)
00069 
00070 manage_addKupuEditorForm = PageTemplateFile('addKupuEditor.pt', globals())
00071 
00072 def createKupuEditor(parent, filepath, id=None):
00073     """Adds either a DirectoryView or a derivative object.
00074     """
00075     info = _dirreg.getDirectoryInfo(filepath)
00076     if info is None:
00077         raise ValueError('Not a registered directory: %s' % filepath)
00078     if not id:
00079         id = path.split(filepath)[-1]
00080     else:
00081         id = str(id)
00082     ob = KupuEditor(id, filepath)
00083     parent._setObject(id, ob)
00084 
00085 def manage_addKupuEditor(self, filepath="Products/kupu/common",
00086                          id=None, REQUEST=None):
00087     """Adds either an kupu editor object
00088     """
00089     createKupuEditor(self, filepath, id)
00090     if REQUEST is not None:
00091         return self.manage_main(self, REQUEST)