bugfix : ancrage du film toujours en bas.
[Portfolio.git] / skins / lightboxcontext.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 bsize = 20
6 options = {}
7
8 uidh = getToolByName(context, 'portal_uidhandler')
9 utool = getToolByName(context, 'portal_url')
10 atool = getToolByName(context, 'portal_actions')
11 pptool = getToolByName(context, 'portal_photo_print', None)
12 portal_url = utool()
13 lightboxUrl = context.absolute_url()
14 portal = utool.getPortalObject()
15 portalDepth = len(portal.getPhysicalPath())
16 req = context.REQUEST
17 toUrl = req.physicalPathToURL
18 resp = req.RESPONSE
19 selDict = req.SESSION.get('objects_selection_dict', {})
20
21 if traverse_subpath[-1] == 'photo_view_ajax' :
22 photoSubPath = traverse_subpath[:-1]
23 ajax = True
24 else :
25 photoSubPath = traverse_subpath
26 ajax = False
27
28 photo = portal.restrictedTraverse(photoSubPath)
29 photouid = uidh.register(photo)
30
31 lightboxUids = context.getUidList()
32
33 if pptool :
34 buyable = bool(pptool.getPrintingOptionsFor(photo))
35 sd = context.session_data_manager.getSessionData(create=1)
36 cart = sd.get('cart', None)
37 if cart and cart.locked :
38 buyable = False
39 else :
40 buyable = False
41 options['buyable'] = buyable
42
43 infos = []
44 posOfPhoto = 0
45
46 if ajax == True :
47 try : posOfPhoto = lightboxUids.index(photouid)
48 except ValueError : pass
49 options['backToContextUrl'] = '%s?b_start:int=%s' % (lightboxUrl, posOfPhoto/bsize*bsize)
50 relPhotoPath = '/'.join(photo.getPhysicalPath()[portalDepth:])
51 lastBcUrl = '%s/lightboxcontext/%s' % (lightboxUrl, relPhotoPath)
52 options['lastBcUrl'] = lastBcUrl
53 meth = getattr(photo, 'photo_view_ajax_template')
54 return meth(**options)
55
56
57 for i, uid in enumerate(lightboxUids) :
58 b = uidh.getBrain(uid)
59 size = b.getThumbnailSize
60 size = {'width':int(size['width']/2.0), 'height':int(size['height']/2.0)}
61
62 className = selDict.has_key(uid) and 'selected' or ''
63 if uid == photouid :
64 className = ('%s displayed' % className).lstrip()
65 posOfPhoto = i
66
67 relPhotoPath = '/'.join(b.getPath().split('/')[portalDepth:])
68 href = '%s/lightboxcontext/%s' % (lightboxUrl, relPhotoPath)
69
70 d = {'src': '%s/getThumbnail' % b.getURL()
71 ,'href': href
72 ,'thumbSize': size
73 ,'title' : b.Title
74 ,'className': className
75 , 'index': i
76 }
77 infos.append(d)
78
79 if posOfPhoto > 0 :
80 previous = infos[posOfPhoto - 1]['href']
81 else :
82 previous = infos[0]['href']
83
84 if posOfPhoto < len(infos) -1 :
85 next = infos[posOfPhoto + 1]['href']
86 else :
87 next = infos[-1]['href']
88
89 contextInfos = {'infos':infos,
90 'isSelected': selDict.has_key(photouid),
91 'backUrl' : '%s?b_start:int=%s' % (lightboxUrl, posOfPhoto/bsize*bsize),
92 'index' : posOfPhoto,
93 'previous' : previous,
94 'next' : next,
95 'reBaseCtxUrl':'/^%s/' % ('%s/lightboxcontext/' % lightboxUrl).replace('/', '\/'),
96 'canonicalUrl': "'%s/'" % portal_url}
97
98 options['contextInfos'] = contextInfos
99
100 # breadcrumbs customization
101 breadcrumbs = context.breadcrumbs()
102 breadcrumbs.append(
103 {'id' : photo.getId()
104 ,'title' : photo.title_or_id()
105 , 'url' : req.ACTUAL_URL}
106 )
107
108 options['breadcrumbs'] = breadcrumbs
109
110
111 ti = photo.getTypeInfo()
112 method_id = ti.queryMethodID('view', context=photo)
113 meth = getattr(photo, method_id)
114 return meth(req, resp, **options)