Factorisation / bugfix.
[Portfolio.git] / skins / selection_view.py
1 ##parameters=
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 req = context.REQUEST
7 utool = getToolByName(context, 'portal_url')
8 portal = utool.getPortalObject()
9 portal_url = utool()
10
11 # check if a lightbox is currently selected
12 lightboxpath = req.SESSION.get('lightboxpath', None)
13 selectionIsLightbox = False
14 if lightboxpath is not None :
15 try :
16 lightbox = portal.restrictedTraverse(lightboxpath)
17 selectionIsLightbox = True
18 except:
19 req.SESSION.set('lightboxpath', None)
20
21 # breadcrumbs customization
22 if selectionIsLightbox :
23 lastBcTitle = '%s (%s)' % (_('My selection'), lightbox.title_or_id())
24 else :
25 lastBcTitle = _('My selection')
26
27 breadcrumbs = [
28 { 'id' : 'root'
29 , 'title' : portal.title
30 , 'url' : portal_url},
31
32 {'id' : 'selection_view'
33 ,'title' : lastBcTitle
34 , 'url' : '%s/selection_view' % portal_url}
35 ]
36
37
38 options = {}
39 options.update(context.getSelectionPhotosInfos())
40 options['container_type'] = 'selection'
41 options['selectionIsLightbox'] = selectionIsLightbox
42 options['breadcrumbs'] = breadcrumbs
43
44 if selectionIsLightbox :
45 options['lightbox'] = lightbox
46 else :
47 options['selectionName'] = 'not saved yet'
48
49 return context.selection_view_template(**options)