Ajout select option de tri.
[Portfolio.git] / skins / selectioncontext.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 options = {}
6
7 uidh = getToolByName(context, 'portal_uidhandler')
8 utool = getToolByName(context, 'portal_url')
9 atool = getToolByName(context, 'portal_actions')
10 pptool = getToolByName(context, 'portal_photo_print', None)
11 portal_url = utool()
12 selectionUrl = atool.getActionInfo('user/selection')['url']
13 portal = utool.getPortalObject()
14 portalDepth = len(portal.getPhysicalPath())
15 req = context.REQUEST
16 toUrl = req.physicalPathToURL
17 resp = req.RESPONSE
18 bsize = portal.getProperty('default_batch_size', 20)
19
20 if traverse_subpath[-1] == 'photo_view_ajax' :
21 photoSubPath = traverse_subpath[:-1]
22 ajax = True
23 else :
24 photoSubPath = traverse_subpath
25 ajax = False
26
27 photo = portal.restrictedTraverse(photoSubPath)
28 photouid = uidh.register(photo)
29
30 lightboxpath = req.SESSION.get('lightboxpath', None)
31 selectionIsLightbox = False
32 if lightboxpath is None :
33 selection = req.SESSION.get('objects_selection', [])
34 else :
35 try :
36 lightbox = portal.restrictedTraverse(lightboxpath)
37 selection = lightbox.getUidList()
38 selectionIsLightbox = True
39 except:
40 req.SESSION.set('lightboxpath', None)
41 selection = req.SESSION.get('objects_selection', [])
42
43 if pptool :
44 buyable = bool(pptool.getPrintingOptionsFor(photo))
45 sd = context.session_data_manager.getSessionData(create=1)
46 cart = sd.get('cart', None)
47 if cart and cart.locked :
48 buyable = False
49 else :
50 buyable = False
51 options['buyable'] = buyable
52
53 infos = []
54 posOfPhoto = 0
55
56 if ajax == True :
57 try : posOfPhoto = selection.index(photouid)
58 except ValueError : pass
59 options['backToContextUrl'] = '%s?b_start:int=%s' % (selectionUrl, posOfPhoto/bsize*bsize)
60 photoPath = list(photo.getPhysicalPath())
61 photoPath.insert(portalDepth, 'selectioncontext')
62 options['lastBcUrl'] = toUrl(photoPath)
63 app = context.restrictedTraverse('/')
64 meth = app.restrictedTraverse(photo.getPhysicalPath() + ('photo_view_ajax_template',))
65 return meth(req, resp, **options)
66
67
68 for i, uid in enumerate(selection) :
69 b = uidh.getBrain(uid)
70 size = b.getThumbnailSize
71 size = {'width':int(size['width']/2.0), 'height':int(size['height']/2.0)}
72
73 if uid == photouid :
74 className = 'selected displayed'
75 posOfPhoto = i
76 else :
77 className = 'selected'
78
79 path = b.getPath().split('/')
80 path.insert(portalDepth, 'selectioncontext')
81
82 d = {'src': '%s/getThumbnail' % b.getURL()
83 ,'href': toUrl(path)
84 ,'thumbSize': size
85 ,'title' : b.Title
86 ,'className': className
87 , 'index': i
88 }
89 infos.append(d)
90
91 if posOfPhoto > 0 :
92 previous = infos[posOfPhoto - 1]['href']
93 else :
94 previous = infos[0]['href']
95
96 if posOfPhoto < len(infos) -1 :
97 next = infos[posOfPhoto + 1]['href']
98 else :
99 next = infos[-1]['href']
100
101
102 contextInfos = {'infos':infos,
103 'isSelected':True,
104 'backUrl' : '%s?b_start:int=%s' % (selectionUrl, posOfPhoto/bsize*bsize),
105 'index' : posOfPhoto,
106 'previous' : previous,
107 'next' : next,
108 'reBaseCtxUrl':'/^%s/' % (portal_url+'/selectioncontext/').replace('/', '\/'),
109 'canonicalUrl': "'%s/'" % portal_url}
110
111 options['contextInfos'] = contextInfos
112
113 # breadcrumbs customization
114 if selectionIsLightbox :
115 lastBcTitle = '%s (%s)' % (_('My selection'), lightbox.title_or_id())
116 else :
117 lastBcTitle = _('My selection')
118
119 breadcrumbs = [
120 { 'id' : 'root'
121 , 'title' : portal.title
122 , 'url' : portal_url},
123
124 {'id' : 'selection_view'
125 ,'title' : lastBcTitle
126 , 'url' : selectionUrl},
127
128 {'id' : photo.getId()
129 ,'title' : photo.title_or_id()
130 , 'url' : req.ACTUAL_URL}
131 ]
132
133 options['breadcrumbs'] = breadcrumbs
134
135
136 ti = photo.getTypeInfo()
137 method_id = ti.queryMethodID('view', context=photo)
138 app = context.restrictedTraverse('/')
139 meth = app.restrictedTraverse(photo.getPhysicalPath() + (method_id,))
140 return meth(req, resp, **options)