bugfix
[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
42 from PloneMisc import IndexIterator, Batch
43 import patch
44
45 from AccessControl import allow_module, allow_class
46
47
48 contentClasses = (File.File, Folder.PlinnFolder, HugePlinnFolder.HugePlinnFolder, Topic.Topic )
49
50 contentConstructors = (File.addFile, Folder.manage_addPlinnFolder, HugePlinnFolder.manage_addHugePlinnFolder, Topic.addTopic)
51
52 tools = ( MembershipTool.MembershipTool
53 , MemberDataTool.MemberDataTool
54 , GroupsTool.GroupsTool
55 , GroupDataTool.GroupDataTool
56 , RegistrationTool.RegistrationTool
57 , CalendarTool.CalendarTool
58 , AttachmentTool.AttachmentTool
59 )
60
61 # register files extensions
62 registerFileExtension('ttf', FSFile)
63 registerFileExtension('eot', FSFile)
64 registerFileExtension('cur', FSFile)
65
66 def initialize(registrar) :
67
68 allow_module('quopri')
69 allow_module('Products.Plinn.PloneMisc')
70 allow_class(IndexIterator)
71 allow_class(Batch)
72
73 core_cmf_utils.ContentInit(
74 'Plinn',
75 content_types = contentClasses,
76 permission = AddPortalContent,
77 extra_constructors = contentConstructors,
78 ).initialize(registrar)
79
80 core_cmf_utils.ToolInit('Plinn Tool',
81 tools = tools,
82 icon = 'tool.gif'
83 ).initialize(registrar)
84
85
86
87
88 # Monkey...
89 # all tags are good !
90 validTags = default_cmf_utils.NASTY_TAGS.copy()
91 for tag in validTags.keys() :
92 validTags[tag] = 1
93
94 VALID_TAGS = {'font': 1, 'param' : 1, 'iframe' : 1}
95
96 validTags.update(VALID_TAGS)
97
98 default_cmf_utils.NASTY_TAGS = {}
99 default_cmf_utils.VALID_TAGS.update(validTags)
100
101 # the plinn portal_calendar is a also a "SPECIAL PROVIDER"
102 # TODO: vérifier l'impact
103 # import Products.CMFCore.exportimport.actions
104 # Products.CMFCore.exportimport.actions._SPECIAL_PROVIDERS += ('portal_calendar',)
105
106
107 # monkey-patch de getIcon qui est foirasse dans CMF2.2 :
108 # les icônes ne s'affichent pas correctement dans la ZMI
109 # lorqu'on y accède par un virtual host apache.
110 from urllib import quote
111 from Products.CMFCore.utils import getToolByName
112
113 def getIcon(self, relative_to_portal=0):
114 """
115 Using this method allows the content class
116 creator to grab icons on the fly instead of using a fixed
117 attribute on the class.
118 """
119 ti = self.getTypeInfo()
120 if ti is not None:
121 icon = quote(ti.getIcon())
122 if icon:
123 if relative_to_portal:
124 return icon
125 else:
126 # Relative to REQUEST['BASEPATH1']
127 portal_url = getToolByName( self, 'portal_url' )
128 res = portal_url(relative=1) + '/' + icon
129 while res[:1] == '/':
130 res = res[1:]
131 return res
132 return 'misc_/OFSP/dtmldoc.gif'
133
134 icon = getIcon # For the ZMI
135
136 from Products.CMFCore.DynamicType import DynamicType
137 DynamicType.getIcon = getIcon
138 DynamicType.icon = getIcon