Copie de MosaicDocument à partir de :
[MosaicDocument.git] / StringSlot.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 from Products.CMFCore.permissions import View, ModifyPortalContent
21
22 factory_type_information = ( {'id' : 'String Slot',
23 'meta_type' : 'String Slot',
24 'description' : "String Slot for Mosaic Document",
25 'icon' : 'mosaic_tool/str_icon.gif',
26 'product' : 'MosaicDocument',
27 'factory' : 'addStringSlot',
28 'immediate_view' : 'view',
29 'actions' :
30 ({'id' : 'view',
31 'name' : 'View',
32 'action' : 'slot_string_view',
33 'permissions' : (View, )
34 },
35
36 {'id' : 'edit',
37 'name' : 'Edit',
38 'action' : 'slot_string_form',
39 'permissions' : (ModifyPortalContent, )
40 },
41 )
42 },
43
44 {'id' : 'Text Slot',
45 'meta_type' : 'Text Slot',
46 'description' : "Text Slot for Mosaic Document",
47 'icon' : 'mosaic_tool/txt_icon.gif',
48 'product' : 'MosaicDocument',
49 'factory' : 'addStringSlot',
50 'immediate_view' : 'view',
51 'actions' :
52 ({'id' : 'view',
53 'name' : 'View',
54 'action' : 'slot_text_view',
55 'permissions' : (View, )
56 },
57
58 {'id' : 'edit',
59 'name' : 'Edit',
60 'action' : 'slot_text_form',
61 'permissions' : (ModifyPortalContent, )
62 },
63 )
64 },
65
66 {'id' : 'List Slot',
67 'meta_type' : 'List Slot',
68 'description' : "List Slot for Mosaic Document",
69 'icon' : 'mosaic_tool/str_icon.gif',
70 'product' : 'MosaicDocument',
71 'factory' : 'addStringSlot',
72 'immediate_view' : 'view',
73 'actions' :
74 ({'id' : 'view',
75 'name' : 'View',
76 'action' : 'slot_list_view',
77 'permissions' : (View, )
78 },
79
80 {'id' : 'edit',
81 'name' : 'Edit',
82 'action' : 'slot_text_form',
83 'permissions' : (ModifyPortalContent, )
84 },
85 )
86 },
87 )
88
89 from AccessControl import ClassSecurityInfo
90 from Globals import InitializeClass
91 from Products.CMFCore.Expression import Expression
92 from Products.CMFDefault.Document import Document
93 from OFS.PropertyManager import PropertyManager
94 from BaseSlot import BaseSlot
95
96 class StringSlot(BaseSlot, Document, PropertyManager) :
97 """String Slot"""
98 meta_type = 'String Slot'
99 _editableFields = ('text', 'text_format', 'size', 'cols', 'rows')
100 _indexableFields = ('text',)
101
102 manage_options = Document.manage_options[:2] + PropertyManager.manage_options + Document.manage_options[2:]
103
104 _properties = ({'id' : 'choices', 'type' : 'lines', 'mode' : 'w'},
105 {'id' : 'castOperator', 'type' : 'string', 'mode' : 'w'},
106 {'id' : 'size', 'type' : 'int', 'mode' : 'w'},
107 {'id' : 'cols', 'type' : 'int', 'mode' : 'w'},
108 {'id' : 'rows', 'type' : 'int', 'mode' : 'w'},
109 {'id' : 'url_expression', 'type': 'expr', 'mode' : 'w'})
110
111 security = ClassSecurityInfo()
112
113
114 def __init__(self, id, text='', text_format='plain',
115 choices = [], castOperator = 'string', size = 60,
116 cols=50, rows=50, url_expression = None) :
117
118 Document.__init__(self, id, text_format = text_format, text = text)
119
120 self.choices = choices
121 self.castOperator = castOperator
122 self.size = size
123 self.cols = cols
124 self.rows = rows
125 if url_expression is None :
126 self.url_expression = Expression("python:None")
127 else :
128 self.url_expression = url_expression
129
130 security.declareProtected(ModifyPortalContent, 'setFormat')
131 def setFormat(self, format):
132 """ Set text format and Dublin Core resource format.
133 """
134 value = str(format)
135 if value == 'text/html' or value == 'html':
136 self.text_format = 'html'
137 elif value == 'text/plain':
138 if self.text_format not in ('structured-text', 'plain'):
139 self.text_format = 'structured-text'
140 elif value == 'plain':
141 self.text_format = 'plain'
142 else:
143 self.text_format = 'structured-text'
144
145
146 InitializeClass(StringSlot)
147
148
149 def addStringSlot(dispatcher, id, text='', text_format='plain',
150 choices = [], castOperator = 'string', size=60,
151 cols=50, rows=50, url_expression = None) :
152 """
153 Add a new TextSlot object.
154 """
155 stringSlot = StringSlot(id,
156 text=text,
157 text_format=text_format,
158 choices=choices,
159 castOperator=castOperator,
160 size=size,
161 cols=cols,
162 rows=rows,
163 url_expression=url_expression)
164 parentContainer = dispatcher.Destination()
165 parentContainer._setObject(id, stringSlot)