From b6d96cd5994f160b56cb89f83555cf9c6e2a4446 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Pin?= Date: Wed, 25 Dec 2013 17:48:38 +0100 Subject: [PATCH] =?utf8?q?Renommage=20des=20=C3=A9l=C3=A9ments=20avec=20?= =?utf8?q?=C3=A9dition=20des=20titres=20et=20des=20ids=20en=20une=20seule?= =?utf8?q?=20op=C3=A9ration.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- skins/custom_control/folder_rename_control.py | 57 ++++++++++----- skins/custom_generic/folder_rename_form.py | 46 ++++++------ .../custom_generic/folder_rename_template.pt | 71 ++++++++++--------- 3 files changed, 94 insertions(+), 80 deletions(-) diff --git a/skins/custom_control/folder_rename_control.py b/skins/custom_control/folder_rename_control.py index 4fc1163..1f0ae27 100755 --- a/skins/custom_control/folder_rename_control.py +++ b/skins/custom_control/folder_rename_control.py @@ -1,26 +1,45 @@ -##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 diff --git a/skins/custom_generic/folder_rename_form.py b/skins/custom_generic/folder_rename_form.py index 731bcf1..b643e76 100644 --- a/skins/custom_generic/folder_rename_form.py +++ b/skins/custom_generic/folder_rename_form.py @@ -1,4 +1,4 @@ -##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 @@ -8,42 +8,36 @@ portal_url = utool() 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) diff --git a/skins/custom_generic/folder_rename_template.pt b/skins/custom_generic/folder_rename_template.pt index 631c004..f6fe694 100644 --- a/skins/custom_generic/folder_rename_template.pt +++ b/skins/custom_generic/folder_rename_template.pt @@ -1,36 +1,37 @@ - - - - -

Rename Items

-
- - -
- - - - - - - -
ID - to
- - -
- - + + +

Rename Items

+
+
+ + + + + + + + + + + + + +

Title
URL
+ + + + + + • + +
+ + +
+ -- 2.20.1