Copie de MosaicDocument à partir de :
[MosaicDocument.git] / MosaicDocument.py
1 # (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
2 # (c) 2003 Benoît PIN <mailto:pin@cri.ensmp.fr>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 # 02111-1307, USA.
17 #
18
19
20
21 from AccessControl import ClassSecurityInfo
22 from Globals import InitializeClass
23 from Products.CMFCore.permissions import View, ModifyPortalContent, AccessContentsInformation
24 from Products.CMFCore.PortalContent import PortalContent
25 from Products.CMFDefault.DublinCore import DefaultDublinCoreImpl
26 from Products.CMFCore.utils import getToolByName
27
28 from MosaicBlock import MosaicBlock
29
30 factory_type_information = (
31 {'id': 'Mosaic Document',
32 'title': '_mosaic_document_',
33 'content_icon': 'mosaic_icon.png',
34 'product': 'MosaicDocument',
35 'factory': 'addMosaicDocument',
36 'meta_type': 'Mosaic Document',
37 'immediate_view': 'mosaicdocument_edit_form',
38 'allow_discussion': 0,
39 'filter_content_types': 0,
40 'actions': ({'id': 'view',
41 'name': 'View',
42 'action': 'mosaicdocument_view',
43 'permissions': (View,)},
44
45 {'id': 'edit',
46 'name': 'Edit',
47 'action': 'mosaicdocument_edit_form',
48 'permissions': (ModifyPortalContent,)},
49
50 {'id': 'metadata',
51 'name': 'Metadata',
52 'action': 'metadata_edit_form',
53 'visible': 0,
54 'permissions': (ModifyPortalContent, )},
55
56 ),
57 },
58 )
59
60
61 class MosaicDocument(MosaicBlock, PortalContent, DefaultDublinCoreImpl) :
62 """
63 Mosaic Document
64 """
65 meta_type = 'Mosaic Document'
66 _isRootBlock = 1
67 isPrincipiaFolderish = 0
68
69 security = ClassSecurityInfo()
70
71 def indexObject(self) :
72 if getattr(self, 'noIndex', None) : return
73 PortalContent.indexObject(self)
74
75 unindexObject = PortalContent.unindexObject
76
77 def reindexObject(self, idxs=[]) :
78 if getattr(self, 'noIndex', None) : return
79 PortalContent.reindexObject(self, idxs=idxs)
80
81 setTitle = DefaultDublinCoreImpl.setTitle
82 setDescription = DefaultDublinCoreImpl.setDescription
83
84 Title = DefaultDublinCoreImpl.Title
85 Description = DefaultDublinCoreImpl.Description
86 Type = DefaultDublinCoreImpl.Type
87
88
89 def __init__(self, id, rules=None, initSubObjects=None, **kw) :
90 DefaultDublinCoreImpl.__init__(self, **kw)
91 self.id = id
92 self._blockRules = rules
93 self._initSubObjects(initSubObjects)
94
95 def _initSubObjects(self, subObjects) :
96 pass
97
98 security.declareProtected(View, 'SearchableText')
99 def SearchableText(self) :
100 """
101 Sets new permissions/roles after this object changed levels
102 or after one of its levels changed of reviewers/readers.
103 """
104 return '%s %s %s' % (self.title, self.description, MosaicBlock.SearchableText(self))
105
106
107 InitializeClass(MosaicDocument)
108
109 # factory
110 def addMosaicDocument(dispatcher, id, REQUEST=None, **kw) :
111 """Ajoute Mosaic Document"""
112 ob = MosaicDocument(id, **kw)
113 dispatcher.Destination()._setObject(id, ob)
114 if REQUEST :
115 REQUEST.RESPONSE.redirect(dispatcher.DestinationURL() + 'manage_main')
116
117
118
119
120 from Products.CMFCore.Expression import Expression as CMFExpression
121
122 class Expression(CMFExpression) :
123 def __call__(self, econtext=None) :
124 """ render the result of expression if an expression context is given
125 else the source text
126 """
127 if econtext :
128 return CMFExpression.__call__(self, econtext)
129 else :
130 return self.text
131
132 def __len__(self) : return 0