[3296] | 1 | ## Controller Python Script "folder_position" |
---|
| 2 | ##title=Move objects in a ordered folder |
---|
| 3 | ##bind container=container |
---|
| 4 | ##bind context=context |
---|
| 5 | ##bind namespace= |
---|
| 6 | ##bind script=script |
---|
| 7 | ##bind state=state |
---|
| 8 | ##bind subpath=traverse_subpath |
---|
| 9 | ##parameters=position, id, template_id='folder_contents' |
---|
| 10 | ## |
---|
| 11 | |
---|
| 12 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
| 13 | from Products.CacheSetup import config |
---|
| 14 | |
---|
| 15 | position=position.lower() |
---|
| 16 | |
---|
| 17 | if position=='up': |
---|
| 18 | context.moveObjectsUp(id) |
---|
| 19 | elif position=='down': |
---|
| 20 | context.moveObjectsDown(id) |
---|
| 21 | elif position=='top': |
---|
| 22 | context.moveObjectsToTop(id) |
---|
| 23 | elif position=='bottom': |
---|
| 24 | context.moveObjectsToBottom(id) |
---|
| 25 | # order folder by field |
---|
| 26 | # id in this case is the field |
---|
| 27 | elif position=='ordered': |
---|
| 28 | context.orderObjects(id) |
---|
| 29 | |
---|
| 30 | context.plone_utils.reindexOnReorder(context) |
---|
| 31 | |
---|
| 32 | msg=_(u'Item\'s position has changed.') |
---|
| 33 | context.plone_utils.addPortalMessage(msg) |
---|
| 34 | |
---|
| 35 | new_context = context.portal_cache_settings |
---|
| 36 | pt = context.portal_type |
---|
| 37 | path = '' |
---|
| 38 | |
---|
| 39 | if pt == config.TOOL_TYPE: |
---|
| 40 | path = 'cache_policy_config' |
---|
| 41 | else: |
---|
| 42 | new_context = new_context.getDisplayPolicy() |
---|
| 43 | if pt == config.RULEFOLDER_TYPE: |
---|
| 44 | path = 'rules' |
---|
| 45 | elif pt == config.HEADERSETFOLDER_TYPE: |
---|
| 46 | path = 'headersets' |
---|
| 47 | |
---|
| 48 | target = '%s/%s' %(new_context.absolute_url(), path) |
---|
| 49 | return context.REQUEST.RESPONSE.redirect(target) |
---|
| 50 | |
---|