Preview dans ckeditor : y'a une couille avec la locasization. On met ça en stand-by…
[Plinn.git] / skins / custom_generic / folder_contents.py
1 ##parameters=b_start=0, key='', reverse=0, ids=(), items_copy='', items_cut='', items_delete='', items_new='', items_paste='', items_rename='', items_up='', items_down='', items_top='', items_bottom='', items_sort='', template='', macro='', ajax='',**others
2 ##
3 from Products.Plinn.PloneMisc import Batch
4 from DateTime import DateTime
5 locale_date_fmt = context.locale_date_fmt()
6 from ZTUtils import make_query
7 from Products.CMFCore.utils import getToolByName
8 from Products.CMFDefault.permissions import AddPortalContent
9 from Products.CMFDefault.permissions import DeleteObjects
10 from Products.CMFDefault.permissions import ListFolderContents
11 from Products.CMFDefault.permissions import ManageProperties
12 from Products.CMFDefault.permissions import ViewManagementScreens
13 from Products.CMFDefault.permissions import ModifyPortalContent
14 from Products.CMFDefault.utils import html_marshal
15
16 mtool = getToolByName(script, 'portal_membership')
17 checkPermission = mtool.checkPermission
18 utool = getToolByName(script, 'portal_url')
19 portal_url = utool()
20
21
22 form = context.REQUEST.form
23 default_target = 'object/folderContents'
24 default_kw = {'b_start': b_start, 'key': key, 'reverse': reverse, 'ajax' : ajax}
25 if items_copy :
26 if ajax : default_kw['syncFragments']=['rightCell']
27 if context.validateItemIds(**form) and \
28 context.folder_copy_control(**form) and \
29 context.setRedirect(context, default_target, **default_kw):
30 return
31 elif items_cut :
32 if ajax : default_kw['syncFragments']=['rightCell']
33 if context.validateItemIds(**form) and \
34 context.folder_cut_control(**form) and \
35 context.setRedirect(context, default_target, **default_kw):
36 return
37 elif items_delete and \
38 context.validateItemIds(**form) and \
39 context.folder_delete_control(**form) and \
40 context.setRedirect(context, default_target, **default_kw):
41 return
42 elif items_new and \
43 context.setRedirect(context, 'object/new', **default_kw):
44 return
45 elif items_paste :
46 if ajax : default_kw['syncFragments']=['rightCell']
47 if context.folder_paste_control(**form) and \
48 context.setRedirect(context, default_target, **default_kw):
49 return
50 elif items_rename and \
51 context.validateItemIds(**form) and \
52 context.setRedirect(context, 'object/rename_items', ids=ids,
53 **default_kw):
54 return
55 elif items_sort and \
56 context.folder_sort_control(**form) and \
57 context.setRedirect(context, default_target, b_start=b_start):
58 return
59 elif items_up and \
60 context.validateItemIds(**form) and \
61 context.folder_up_control(**form) and \
62 context.setRedirect(context, default_target, **default_kw):
63 return
64 elif items_down and \
65 context.validateItemIds(**form) and \
66 context.folder_down_control(**form) and \
67 context.setRedirect(context, default_target, **default_kw):
68 return
69 elif items_top and \
70 context.validateItemIds(**form) and \
71 context.folder_top_control(**form) and \
72 context.setRedirect(context, default_target, **default_kw):
73 return
74 elif items_bottom and \
75 context.validateItemIds(**form) and \
76 context.folder_bottom_control(**form) and \
77 context.setRedirect(context, default_target, **default_kw):
78 return
79
80
81 options = {}
82
83 items_add_allowed = checkPermission(AddPortalContent, context)
84 upitems_list_allowed = checkPermission(ListFolderContents, context, 'aq_parent')
85 manage_props_allowed = checkPermission(ManageProperties, context)
86
87 # information pour remonter au dossier parent
88 up_info = {}
89 if upitems_list_allowed:
90 up_obj = context.aq_parent
91 if hasattr(up_obj, 'portal_url'):
92 up_url = up_obj.getActionInfo('object/folderContents')['url']
93 up_info = { 'icon': '%s/UpFolder_icon.gif' % portal_url,
94 'id': up_obj.getId(),
95 'url': up_url }
96 else:
97 up_info = { 'icon': '',
98 'id': 'Root',
99 'url': '' }
100 options['up_info'] = up_info
101
102 target = context.getActionInfo(default_target)['url']
103
104 if not key:
105 (key, reverse) = context.getDefaultSorting()
106 is_default = 1
107 elif (key, reverse) == context.getDefaultSorting():
108 is_default = 1
109 else:
110 is_default = 0
111
112 columns = ( {'key': 'Lock',
113 'title': '',
114 'width': '16',
115 'colspan': None}
116 , {'key': 'Type',
117 'title': 'Type',
118 'width': None,
119 'colspan': '2'}
120 , {'key': 'title_or_id',
121 'title': 'Name',
122 'width': None,
123 'colspan': None}
124 , {'key': 'modified',
125 'title': 'Last Modified',
126 'width': None,
127 'colspan': None}
128 , {'key': 'position',
129 'title': 'Position',
130 'width': None,
131 'colspan': None }
132 )
133
134 for column in columns:
135 images = []
136 if key == column['key'] :
137 if not is_default and manage_props_allowed :
138 images.append( {'src' : getattr(context, 'set_default_sorting.gif').absolute_url(),
139 'alt' : 'Set Sorting as Default',
140 'id' : 'SetSortingAsDefault',
141 'href': '%s?%s' % (target, make_query(items_sort=True,
142 key=key,
143 reverse= (key != 'position' and [reverse] or [False])[0] )
144 )
145 }
146 )
147
148 if key != 'position' :
149 if reverse :
150 toggleImg = getattr(context, 'arrowDown.gif')
151 alt = 'descending sort'
152 else :
153 toggleImg = getattr(context, 'arrowUp.gif')
154 alt = 'ascending sort'
155 query = make_query(key=column['key'], reverse = not reverse)
156 else :
157 toggleImg = getattr(context, 'arrowUp.gif')
158 alt = 'ascending sort'
159 query = make_query(key=column['key'])
160 images.append( {'src' : toggleImg.absolute_url(), 'alt' : alt} )
161 else :
162 if key != 'position' :
163 query = make_query(key=column['key'], reverse = reverse)
164 else :
165 query = make_query(key=column['key'])
166
167 column['url'] = '%s?%s' % (target, query)
168 column['images'] = images
169
170 context.filterCookie()
171 folderfilter = context.REQUEST.get('folderfilter', '')
172 filter = context.decodeFolderFilter(folderfilter)
173 items = context.listNearestFolderContents(contentFilter=filter)
174 sort_dir = reverse and 'desc' or 'asc'
175 sortFunc = key in ['Type', 'title_or_id'] and 'nocase' or 'cmp'
176 items = sequence.sort( items, ((key, sortFunc, sort_dir),) )
177 batch_obj = Batch(items, context.default_batch_size, b_start, orphan=0, quantumleap=1)
178 items = []
179 i = 1
180 display_delete_button = False
181 for item in batch_obj:
182 item_icon = item.getIcon(1)
183 item_id = item.getId()
184 item_position = key == 'position' and str(b_start + i) or '...'
185 i += 1
186 item_url = item.absolute_url()
187 try : item_delete_allowed = context.objectIdCanBeDeleted(item_id)
188 except : item_delete_allowed = checkPermission(DeleteObjects, context) # std zope perm
189 if not display_delete_button :
190 display_delete_button = item_delete_allowed
191 items.append(
192 {'lock' : not checkPermission(ModifyPortalContent, item),
193 'checkbox': item_delete_allowed and ('cb_%s' % item_id) or '',
194 'icon': item_icon and ( '%s/%s' % (portal_url, item_icon) ) or '',
195 'id': item_id,
196 'modified': item.modified().strftime(locale_date_fmt),
197 'position': item_position,
198 'title_or_id': item.title_or_id(),
199 'type': item.Type() or None,
200 'url': item_url } )
201
202 options['batch'] = { 'listColumnInfos': tuple(columns),
203 'listItemInfos': tuple(items),
204 'sort_key' : key,
205 'sort_dir' : sort_dir,
206 'batch_obj': batch_obj }
207
208 hidden_vars = []
209 for name, value in html_marshal(**default_kw):
210 hidden_vars.append( {'name': name, 'value': value} )
211
212 # buttons
213 buttons = []
214 if items_add_allowed and context.allowedContentTypes():
215 buttons.append( {'name': 'items_new', 'value': 'New...'} )
216 if items:
217 buttons.append( {'name': 'items_rename', 'value': 'Rename'} )
218
219 if checkPermission(ViewManagementScreens, context) and items:
220 buttons.append( {'name': 'items_cut', 'value': 'Cut'} )
221 buttons.append( {'name': 'items_copy', 'value': 'Copy'} )
222
223 if items_add_allowed and context.cb_dataValid():
224 buttons.append( {'name': 'items_paste', 'value': 'Paste'} )
225
226 if display_delete_button and items:
227 buttons.append( {'name': 'items_delete', 'value': 'Delete'} )
228
229 length = batch_obj.sequence_length
230 is_orderable = manage_props_allowed and (key == 'position') and length > 1
231 is_sortable = manage_props_allowed and not is_default
232 options['form'] = { 'action': target,
233 'listHiddenVarInfos': tuple(hidden_vars),
234 'listButtonInfos': tuple(buttons),
235 'is_orderable': is_orderable,
236 'is_sortable': is_sortable }
237 if not ajax and is_orderable :
238 deltas = range( 1, min(5, length) ) + range(5, length, 5)
239 options['form']['listDeltas'] = tuple(deltas)
240
241 if template and macro :
242 options['template'] = template
243 options['macro'] = macro
244 return context.use_macro(**options)
245 else :
246 options.update(others)
247 return context.folder_contents_template(**options)
248