comments++ install solr debian
[Plinn.git] / skins / custom_control / folder_rename_control.py
1 ##parameters=items, **kw
2 ##title=Rename objects in a folder
3 ##
4 from Products.CMFDefault.exceptions import CopyError
5 from Products.Plinn.utils import translate
6 _ = lambda msg : translate(msg, context)
7
8 ids, new_ids = zip(*[(i['id'], i['new_id']) for i in items])
9 changed = 0
10
11 c = context.aq_explicit
12 for itemInfo in items :
13 item = getattr(c, itemInfo['id'])
14 if item.Title() != itemInfo['title'] :
15 item.setTitle(itemInfo['title'])
16 item.reindexObject()
17 changed = changed + 1
18
19 if not ids == new_ids:
20 try:
21 skiped = context.manage_renameObjects(ids, new_ids)
22 if not skiped :
23 if len(ids) == 1:
24 return context.setStatus(True, _(u'Item renamed.'))
25 else:
26 return context.setStatus(True, _(u'Items renamed.'))
27 else :
28 if len(skiped) == 1 :
29 return context.setStatus(True, _( u'This item has not been renamed: "%s"') % ids[0] )
30 else :
31 return context.setStatus(True
32 , _( u'These items have not been renamed: %s') % \
33 ', '.join(['"%s"' % id for id in ids]) )
34 except CopyError:
35 return context.setStatus(False, _(u'Rename failed.'))
36
37
38 elif not changed :
39 return context.setStatus(False, _(u'Nothing to change.'))
40 else :
41 if changed == 1:
42 return context.setStatus(True, _(u'Item renamed.'))
43 else:
44 return context.setStatus(True, _(u'Items renamed.'))
45