2659868d6b556de50b97f1688ca1c0f957c907aa
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=''
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
16 mtool
= getToolByName(script
, 'portal_membership')
17 checkPermission
= mtool
.checkPermission
18 utool
= getToolByName(script
, 'portal_url')
22 form
= context
.REQUEST
.form
23 default_target
= 'object/folderContents'
24 default_kw
= {'b_start': b_start
, 'key': key
, 'reverse': reverse
, 'ajax' : ajax
}
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
):
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
):
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
):
43 context
.setRedirect(context
, 'object/new', **default_kw
):
46 if ajax
: default_kw
['syncFragments']=['rightCell']
47 if context
.folder_paste_control(**form
) and \
48 context
.setRedirect(context
, default_target
, **default_kw
):
50 elif items_rename
and \
51 context
.validateItemIds(**form
) and \
52 context
.setRedirect(context
, 'object/rename_items', ids
=ids
,
56 context
.folder_sort_control(**form
) and \
57 context
.setRedirect(context
, default_target
, b_start
=b_start
):
60 context
.validateItemIds(**form
) and \
61 context
.folder_up_control(**form
) and \
62 context
.setRedirect(context
, default_target
, **default_kw
):
65 context
.validateItemIds(**form
) and \
66 context
.folder_down_control(**form
) and \
67 context
.setRedirect(context
, default_target
, **default_kw
):
70 context
.validateItemIds(**form
) and \
71 context
.folder_top_control(**form
) and \
72 context
.setRedirect(context
, default_target
, **default_kw
):
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
):
83 items_add_allowed
= checkPermission(AddPortalContent
, context
)
84 upitems_list_allowed
= checkPermission(ListFolderContents
, context
, 'aq_parent')
85 manage_props_allowed
= checkPermission(ManageProperties
, context
)
87 target
= context
.getActionInfo(default_target
)['url']
90 (key
, reverse
) = context
.getDefaultSorting()
92 elif (key
, reverse
) == context
.getDefaultSorting():
97 columns
= ( {'key': 'Lock',
109 , {'key': 'modified',
110 'title': 'Last Modified',
113 # , {'key': 'position',
114 # 'title': 'Position',
119 for column
in columns
:
121 if key
== column
['key'] :
122 if not is_default
and manage_props_allowed
:
123 images
.append( {'src' : getattr(context
, 'set_default_sorting.gif').absolute_url(),
124 'alt' : 'Set Sorting as Default',
125 'id' : 'SetSortingAsDefault',
126 'href': '%s?%s' % (target
, make_query(items_sort
=True,
128 reverse
= (key
!= 'position' and [reverse
] or [False])[0] )
133 if key
!= 'position' :
135 toggleImg
= getattr(context
, 'arrowDown.gif')
136 alt
= 'descending sort'
138 toggleImg
= getattr(context
, 'arrowUp.gif')
139 alt
= 'ascending sort'
140 query
= make_query(key
=column
['key'], reverse
= not reverse
)
142 toggleImg
= getattr(context
, 'arrowUp.gif')
143 alt
= 'ascending sort'
144 query
= make_query(key
=column
['key'])
145 images
.append( {'src' : toggleImg
.absolute_url(), 'alt' : alt
} )
147 if key
!= 'position' :
148 query
= make_query(key
=column
['key'], reverse
= reverse
)
150 query
= make_query(key
=column
['key'])
152 column
['url'] = '%s?%s' % (target
, query
)
153 column
['images'] = images
155 context
.filterCookie()
156 folderfilter
= context
.REQUEST
.get('folderfilter', '')
157 filter = context
.decodeFolderFilter(folderfilter
)
158 items
= context
.listCatalogedContents(contentFilter
=filter)
159 sort_dir
= reverse
and 'desc' or 'asc'
160 sortFunc
= key
in ['Type'] and 'nocase' or 'cmp'
161 items
= sequence
.sort( items
, ((key
, sortFunc
, sort_dir
),) )
162 batch_obj
= Batch(items
, context
.default_batch_size
, b_start
, orphan
=0, quantumleap
=1)
164 display_delete_button
= True # TODO : à revoir
165 for item
in batch_obj
:
166 item_icon
= item
.getIcon
168 item_url
= item
.getURL()
169 #try : item_delete_allowed = context.objectIdCanBeDeleted(item_id)
170 #except : item_delete_allowed = checkPermission(DeleteObjects, context) # std zope perm
171 #if not display_delete_button :
172 # display_delete_button = item_delete_allowed
176 'icon': item_icon
and ( '%s/%s' % (portal_url
, item_icon
) ) or '',
178 'modified': item
.modified
.strftime(locale_date_fmt
),
179 'title_or_id': item
.Title
or item_id
,
180 'type': item
.Type
or None,
183 options
['batch'] = { 'listColumnInfos': tuple(columns
),
184 'listItemInfos': tuple(items
),
185 'firstItemPos' : b_start
+ 1,
187 'sort_dir' : sort_dir
,
188 'batch_obj': batch_obj
}
191 for name
, value
in html_marshal(**default_kw
):
192 hidden_vars
.append( {'name': name
, 'value': value
} )
196 if items_add_allowed
and context
.allowedContentTypes():
197 buttons
.append( {'name': 'items_new', 'value': 'New...'} )
199 buttons
.append( {'name': 'items_rename', 'value': 'Rename'} )
201 if checkPermission(ViewManagementScreens
, context
) and items
:
202 buttons
.append( {'name': 'items_cut', 'value': 'Cut'} )
203 buttons
.append( {'name': 'items_copy', 'value': 'Copy'} )
205 if items_add_allowed
and context
.cb_dataValid():
206 buttons
.append( {'name': 'items_paste', 'value': 'Paste'} )
208 if display_delete_button
and items
:
209 buttons
.append( {'name': 'items_delete', 'value': 'Delete'} )
211 length
= batch_obj
.sequence_length
212 is_orderable
= manage_props_allowed
and (key
== 'position') and length
> 1
213 is_sortable
= manage_props_allowed
and not is_default
214 options
['form'] = { 'action': target
,
215 'listHiddenVarInfos': tuple(hidden_vars
),
216 'listButtonInfos': tuple(buttons
),
217 'is_orderable': is_orderable
,
218 'is_sortable': is_sortable
}
219 if not ajax
and is_orderable
:
220 deltas
= range( 1, min(5, length
) ) + range(5, length
, 5)
221 options
['form']['listDeltas'] = tuple(deltas
)
223 if template
and macro
:
224 options
['template'] = template
225 options
['macro'] = macro
226 return context
.use_macro(**options
)
228 return context
.folder_contents_template(**options
)