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