Début d'implémentation du rafraîchissement des images après modification du tri.
[Portfolio.git] / skins / add_to_selection.py
1 ##parameters=ajax=''
2 from Products.CMFCore.utils import getToolByName
3 from Products.Portfolio.utils import translate
4 def _(message) : return translate(message, context).encode('utf-8')
5
6 uidtool = getToolByName(context, 'portal_uidhandler')
7 utool = getToolByName(context, 'portal_url')
8 portal = utool.getPortalObject()
9 uid = uidtool.register(context)
10
11 sd = context.session_data_manager.getSessionData(create = 1)
12
13 selection = sd.get('objects_selection', [])
14 selDict = sd.get('objects_selection_dict', {})
15
16 lightboxpath = sd.get('lightboxpath', None)
17 selectionIsLightbox = False
18 if lightboxpath is None :
19 selection = sd.get('objects_selection', [])
20 else :
21 try :
22 lightbox = portal.restrictedTraverse(lightboxpath)
23 selection = lightbox.getUidList()
24 selectionIsLightbox = True
25 except KeyError :
26 sd.set('lightboxpath', None)
27 selection = sd.get('objects_selection', [])
28
29
30 if not selDict.has_key(uid) :
31 selDict[uid] = True
32 selection.append(uid)
33 if selectionIsLightbox:
34 lightbox.append(uid)
35 sd['objects_selection'] = selection
36 sd['objects_selection_dict'] = selDict
37 msg = _('%s added to selection.') % context.getPortalTypeName()
38 else :
39 msg = _("This %s is already in the selection.") % context.getPortalTypeName()
40
41 if not ajax:
42 context.setStatus(True, msg)
43 return context.setRedirect(context, 'object/view')