Ajout de 2 modules requis pour le fonctionnement de Plinn.
[Plinn.git] / __init__.py
1 # -*- coding: utf-8 -*-
2 #######################################################################################
3 # Plinn - http://plinn.org #
4 # Copyright (C) 2005-2007 Benoît PIN <benoit.pin@ensmp.fr> #
5 # #
6 # This program is free software; you can redistribute it and/or #
7 # modify it under the terms of the GNU General Public License #
8 # as published by the Free Software Foundation; either version 2 #
9 # of the License, or (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program; if not, write to the Free Software #
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #
19 #######################################################################################
20 """ Plinn implementation of CMFCore.
21
22
23
24 """
25
26 import exceptions
27
28 from Products.CMFCore import utils as core_cmf_utils
29 from Products.CMFDefault import utils as default_cmf_utils
30 from Products.CMFCore.permissions import AddPortalContent
31 from Products.CMFCore.FSFile import FSFile
32 from Products.CMFCore.DirectoryView import registerFileExtension
33 import File, Folder, HugePlinnFolder, Topic
34 import MembershipTool
35 import MemberDataTool
36 import GroupsTool
37 import GroupDataTool
38 import RegistrationTool
39 import CalendarTool
40 import AttachmentTool
41 #from shutdown_dispatcher import ZopeShutdownDispatcher
42
43 from PloneMisc import IndexIterator, Batch
44 from utils import getCPInfo, popCP
45
46 import patch
47
48 from AccessControl import allow_module, allow_class
49
50
51 contentClasses = (File.File, Folder.PlinnFolder, HugePlinnFolder.HugePlinnFolder, Topic.Topic )
52
53 contentConstructors = (File.addFile, Folder.manage_addPlinnFolder, HugePlinnFolder.manage_addHugePlinnFolder, Topic.addTopic)
54
55 tools = ( MembershipTool.MembershipTool
56 , MemberDataTool.MemberDataTool
57 , GroupsTool.GroupsTool
58 , GroupDataTool.GroupDataTool
59 , RegistrationTool.RegistrationTool
60 , CalendarTool.CalendarTool
61 , AttachmentTool.AttachmentTool
62 )
63
64 methods = {
65 'getCPInfo': getCPInfo,
66 'getCPInfo__roles__': None,
67 'popCP' : popCP,
68 'popCP__roles__' : None
69 }
70
71 # register font extensions
72 registerFileExtension('ttf', FSFile)
73 registerFileExtension('eot', FSFile)
74
75 def initialize(registrar) :
76
77 allow_module('quopri')
78 allow_module('Products.Plinn.PloneMisc')
79 allow_class(IndexIterator)
80 allow_class(Batch)
81 app = registrar._ProductContext__app
82 #ZopeShutdownDispatcher(registrar._ProductContext__app)
83
84 core_cmf_utils.ContentInit(
85 'Plinn',
86 content_types = contentClasses,
87 permission = AddPortalContent,
88 extra_constructors = contentConstructors,
89 ).initialize(registrar)
90
91 core_cmf_utils.ToolInit('Plinn Tool',
92 tools = tools,
93 icon = 'tool.gif'
94 ).initialize(registrar)
95
96
97
98
99 # Monkey...
100 # all tags are good !
101 validTags = default_cmf_utils.NASTY_TAGS.copy()
102 for tag in validTags.keys() :
103 validTags[tag] = 1
104
105 VALID_TAGS = {'font': 1, 'param' : 1, 'iframe' : 1}
106
107 validTags.update(VALID_TAGS)
108
109 default_cmf_utils.NASTY_TAGS = {}
110 default_cmf_utils.VALID_TAGS.update(validTags)
111
112 # the plinn portal_calendar is a also a "SPECIAL PROVIDER"
113 # TODO: vérifier l'impact
114 # import Products.CMFCore.exportimport.actions
115 # Products.CMFCore.exportimport.actions._SPECIAL_PROVIDERS += ('portal_calendar',)
116
117
118 # monkey-patch de getIcon qui est foirasse dans CMF2.2 :
119 # les icônes ne s'affichent pas correctement dans la ZMI
120 # lorqu'on y accède par un virtual host apache.
121 from urllib import quote
122 from Products.CMFCore.utils import getToolByName
123
124 def getIcon(self, relative_to_portal=0):
125 """
126 Using this method allows the content class
127 creator to grab icons on the fly instead of using a fixed
128 attribute on the class.
129 """
130 ti = self.getTypeInfo()
131 if ti is not None:
132 icon = quote(ti.getIcon())
133 if icon:
134 if relative_to_portal:
135 return icon
136 else:
137 # Relative to REQUEST['BASEPATH1']
138 portal_url = getToolByName( self, 'portal_url' )
139 res = portal_url(relative=1) + '/' + icon
140 while res[:1] == '/':
141 res = res[1:]
142 return res
143 return 'misc_/OFSP/dtmldoc.gif'
144
145 icon = getIcon # For the ZMI
146
147 from Products.CMFCore.DynamicType import DynamicType
148 DynamicType.getIcon = getIcon
149 DynamicType.icon = getIcon