Merge branch 'dd_ordering' into zope-2.13
[Portfolio.git] / skins / selection_view.py
1 ##parameters=
2 from Products.CMFCore.utils import getUtilityByInterfaceName
3 from Products.Portfolio.utils import translate
4 def _(message) : return translate(message, context).encode('utf-8')
5
6 req = context.REQUEST
7 utool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IURLTool')
8 portal = utool.getPortalObject()
9 portal_url = utool()
10
11 form = req.form
12 fg = form.get
13 sd = context.session_data_manager.getSessionData(create = 1)
14
15 # check if a lightbox is currently selected
16 lightboxpath = sd.get('lightboxpath', None)
17 selectionIsLightbox = False
18 if lightboxpath is not None :
19 try :
20 lightbox = portal.restrictedTraverse(lightboxpath)
21 selectionIsLightbox = True
22 except:
23 sd['lightboxpath'] = None
24
25 # form processing
26 if fg('delete.x') or form.has_key('delete') :
27 selection = sd.get('objects_selection', [])
28 selDict = sd.get('objects_selection_dict', {})
29
30 # get selection from session data or from selected lightbox
31 if not selectionIsLightbox :
32 selection = sd.get('objects_selection', [])
33 else :
34 try :
35 lightbox = portal.restrictedTraverse(lightboxpath)
36 selection = lightbox.getUidList()
37 except KeyError :
38 sd['lightboxpath'] = None
39 selection = sd.get('objects_selection', [])
40
41 # remove items from selection
42 rmCpt = 0
43 for uid in [int(uid) for uid in fg('uids', [])] :
44 if selDict.has_key(uid) :
45 del selDict[uid]
46 selection.remove(uid)
47 if selectionIsLightbox :
48 lightbox.remove(uid)
49 rmCpt = rmCpt + 1
50 sd['objects_selection'] = selection
51 sd['objects_selection_dict'] = selDict
52
53 # ui feedback message
54 if rmCpt :
55 if rmCpt == 1 :
56 msg = _('Photo deselected.')
57 else :
58 msg = _('Deselected photos.')
59 else :
60 msg = _('Nothing to deselect.')
61
62 if fg('ajax') :
63 req.RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8')
64 return '<deleted>%s</deleted>' % msg
65 else :
66 context.setStatus(True, msg)
67
68 # breadcrumbs customization
69 if selectionIsLightbox :
70 lastBcTitle = '%s (%s)' % (_('My selection'), lightbox.title_or_id())
71 else :
72 lastBcTitle = _('My selection')
73
74 breadcrumbs = [
75 { 'id' : 'root'
76 , 'title' : portal.title
77 , 'url' : portal_url},
78
79 {'id' : 'selection_view'
80 ,'title' : lastBcTitle
81 , 'url' : '%s/selection_view' % portal_url}
82 ]
83
84
85 options = {}
86 options.update(context.getSelectionPhotosInfos())
87 options['container_type'] = 'selection'
88 options['selectionIsLightbox'] = selectionIsLightbox
89 options['breadcrumbs'] = breadcrumbs
90
91 if selectionIsLightbox :
92 options['lightbox'] = lightbox
93 else :
94 options['selectionName'] = 'not saved yet'
95
96 return context.selection_view_template(**options)