-##parameters=ids, new_ids, **kw
+##parameters=items, **kw
##title=Rename objects in a folder
##
from Products.CMFDefault.exceptions import CopyError
from Products.Plinn.utils import translate
_ = lambda msg : translate(msg, context)
+ids, new_ids = zip(*[(i['id'], i['new_id']) for i in items])
+changed = 0
+
+c = context.aq_explicit
+for itemInfo in items :
+ item = getattr(c, itemInfo['id'])
+ if item.Title() != itemInfo['title'] :
+ item.setTitle(itemInfo['title'])
+ item.reindexObject()
+ changed = changed + 1
+
if not ids == new_ids:
- try:
- skiped = context.manage_renameObjects(ids, new_ids)
- if not skiped :
- if len(ids) == 1:
- return context.setStatus(True, _(u'Item renamed.'))
- else:
- return context.setStatus(True, _(u'Items renamed.'))
- else :
- if len(skiped) == 1 :
- return context.setStatus(True, _( u'This item has not been renamed: "%s"') % ids[0] )
- else :
- return context.setStatus(True
- , _( u'These items have not been renamed: %s') % \
- ', '.join(['"%s"' % id for id in ids]) )
- except CopyError:
- return context.setStatus(False, _(u'Rename failed.'))
-else:
- return context.setStatus(False, _(u'Nothing to change.'))
+ try:
+ skiped = context.manage_renameObjects(ids, new_ids)
+ if not skiped :
+ if len(ids) == 1:
+ return context.setStatus(True, _(u'Item renamed.'))
+ else:
+ return context.setStatus(True, _(u'Items renamed.'))
+ else :
+ if len(skiped) == 1 :
+ return context.setStatus(True, _( u'This item has not been renamed: "%s"') % ids[0] )
+ else :
+ return context.setStatus(True
+ , _( u'These items have not been renamed: %s') % \
+ ', '.join(['"%s"' % id for id in ids]) )
+ except CopyError:
+ return context.setStatus(False, _(u'Rename failed.'))
+
+
+elif not changed :
+ return context.setStatus(False, _(u'Nothing to change.'))
+else :
+ if changed == 1:
+ return context.setStatus(True, _(u'Item renamed.'))
+ else:
+ return context.setStatus(True, _(u'Items renamed.'))
+
\ No newline at end of file
-##parameters=b_start=0, key='', reverse=0, ids=(), new_ids=(), rename='', cancel='', ajax=''
+##parameters=ids=[], items=[], rename='', cancel='', ajax=''
##
from Products.CMFCore.utils import getToolByName
from Products.CMFDefault.utils import html_marshal
form = context.REQUEST.form
-default_kw = {'b_start': b_start, 'key': key, 'reverse': reverse}
-if ajax :
- default_kw.update({'ajax' : ajax})
if rename and \
context.folder_rename_control(**form) and \
- context.setRedirect(context, 'object/folderContents', **default_kw):
+ context.setRedirect(context, 'object/folderContents', **form):
return
elif cancel and \
- context.setRedirect(context, 'object/folderContents', **default_kw):
+ context.setRedirect(context, 'object/folderContents', **form):
return
-
options = {}
-
c = context.aq_explicit
-raw_items = [ getattr(c, id) for id in ids if hasattr(c, id) ]
-raw_items = [ item for item in raw_items if item.cb_isMoveable() ]
-items = []
-for item in raw_items:
- item_icon = item.getIcon(1)
- items.append( { 'icon': item_icon and ( '%s/%s' % (portal_url, item_icon) ) or '',
- 'id': item.getId(),
- 'title': item.Title(),
- 'type': item.Type() or None } )
-options['batch'] = { 'listItemInfos': tuple(items) }
-target = context.getActionInfo('object/rename_items')['url']
-hidden_vars = []
-default_kw.pop('ajax', None)
-for name, value in html_marshal(**default_kw):
- hidden_vars.append( {'name': name, 'value': value} )
+if not ids :
+ ids = [i['id'] for i in items]
+itemInfos = []
+for id in ids :
+ if hasattr(c, id) :
+ item = getattr(c, id)
+ if item.cb_isMoveable() :
+ item_icon = item.getIcon(1)
+ itemInfos.append( { 'icon': item_icon and ( '%s/%s' % (portal_url, item_icon) ) or '',
+ 'id': item.getId(),
+ 'title': item.Title(),
+ 'type': item.Type() or None } )
+
+options['batch'] = { 'listItemInfos': itemInfos }
+action = context.getActionInfo('object/rename_items')['url']
buttons = []
buttons.append( {'name': 'rename', 'value': 'Rename'} )
buttons.append( {'name': 'cancel', 'value': 'Cancel'} )
-options['form'] = { 'action': target,
- 'listHiddenVarInfos': tuple(hidden_vars),
- 'listButtonInfos': tuple(buttons) }
+options['form'] = {'action': action,
+ 'listButtonInfos': tuple(buttons)}
return context.folder_rename_template(**options)
-<html metal:use-macro="context/main_template/macros/master">
-<body>
-
-<metal:slot metal:fill-slot="header" i18n:domain="cmf_default">
-<h1 i18n:translate="">Rename Items</h1>
-</metal:slot>
-
-<metal:slot metal:fill-slot="main" i18n:domain="cmf_default"
- tal:define="batch options/batch;
- form options/form">
-<form action="members_manage" method="post"
- tal:attributes="action form/action"
-><metal:macro metal:use-macro="context/form_widgets/macros/hidden_vars" />
- <table class="FormLayout">
- <tr tal:repeat="item_info batch/listItemInfos">
- <td width="8%"
- ><img src="" alt="" border="0"
- tal:attributes="src item_info/icon; alt item_info/type"
- i18n:attributes="alt" /></td>
- <td width="20%"
- ><tal:span tal:replace="item_info/id">ID</tal:span>
- <input type="hidden" name="ids:list" value=""
- tal:attributes="value item_info/id" /></td>
- <td width="5%"
- ><strong i18n:translate="">to</strong></td>
- <td
- ><input type="text" name="new_ids:list" value=""
- tal:attributes="value item_info/id" size="20" /></td>
- </tr>
- </table>
- <metal:macro metal:use-macro="context/form_widgets/macros/buttons" />
-</form>
-</metal:slot>
-
-</body>
+<html xmlns:tal="http://xml.zope.org/namespaces/tal"
+ xmlns:metal="http://xml.zope.org/namespaces/metal"
+ xmlns:i18n="http://xml.zope.org/namespaces/i18n"
+ metal:use-macro="context/main_template/macros/master">
+ <body i18n:domain="plinn">
+ <h1 metal:fill-slot="header" i18n:translate="">Rename Items</h1>
+ <div metal:fill-slot="main"
+ tal:define="batch options/batch;
+ form options/form">
+ <form method="post" tal:attributes="action form/action">
+ <table class="listing" cellspacing="0">
+ <tr>
+ <th><br/></th>
+ <th i18n:translate="">Title</th>
+ <th><br/></th>
+ <th i18n:translate="">URL</th>
+ </tr>
+ <tr tal:repeat="item_info batch/listItemInfos">
+ <td>
+ <img src="" alt="" border="0" tal:attributes="src item_info/icon; alt item_info/type" i18n:attributes="alt"/>
+ <input type="hidden" name="noAjax" value="noAjax"/>
+ <input type="hidden" name="items.id:records" value="" tal:attributes="value item_info/id"/>
+ </td>
+ <td>
+ <input type="text" name="items.title:records" tal:attributes="value item_info/title"/>
+ </td>
+ <td>•</td>
+ <td>
+ <input type="text" name="items.new_id:records" value="" tal:attributes="value item_info/id"/>
+ </td>
+ </tr>
+ </table>
+ <metal:macro metal:use-macro="context/form_widgets/macros/buttons"/>
+ </form>
+ </div>
+ </body>
</html>