recompilation du diaporama flash avec flex 4.12.1.
[Portfolio.git] / skins / getPhotoContextInfos.py
1 ##parameters=
2 from ZTUtils import make_query as mq
3 from Products.CMFCore.utils import getToolByName
4 pptool = getToolByName(context, 'portal_photo_print', None)
5 uidtool = getToolByName(context, 'portal_uidhandler')
6 utool = getToolByName(context, 'portal_url')
7 portal = utool.getPortalObject()
8 form = context.REQUEST.form
9 portfolio = context.getParentNode()
10 bsize = portal.getProperty('default_batch_size', 20)
11
12 infos = []
13 index = 0
14 sd = context.session_data_manager.getSessionData(create = 1)
15 selDict = sd.get('objects_selection_dict', {})
16 cart = sd.get('cart', None)
17
18 contextUid = getattr(context, 'cmf_uid', None)
19 if contextUid is not None :
20 contextUid = contextUid()
21 else :
22 uidh = getToolByName(context, 'portal_uidhandler')
23 contextUid = uidtool.register(context)
24 isSelected = selDict.has_key(contextUid)
25
26 for i, p in enumerate(portfolio.listNearestFolderContents(contentFilter={'portal_type' : ['Photo']}, sorted=True)) :
27 if not p.size :
28 continue
29 uid = getattr(p, 'cmf_uid', None)
30 if uid is not None :
31 uid = uid()
32 selected = selDict.has_key(uid)
33 size = p.getThumbnailSize()
34 size = {'width':int(size['width']/2.0), 'height':int(size['height']/2.0)}
35 purl = p.absolute_url()
36 d = {'src': '%s/getThumbnail' % purl
37 ,'href': purl
38 ,'thumbSize':size
39 ,'title' : p.Title()
40 ,'className': (selected and 'selected' or '') + ((p == context) and ' displayed' or '')
41 , 'index': i
42 }
43 if contextUid == uid:
44 index = i
45
46 infos.append(d)
47
48 if pptool :
49 buyable = bool(pptool.getPrintingOptionsFor(context))
50 if cart and cart.locked :
51 buyable = False
52 else :
53 buyable = False
54
55 if index > 0 :
56 previous = infos[index - 1]['href']
57 else :
58 previous = '.'
59
60 if index < len(infos) -1 :
61 next = infos[index + 1]['href']
62 else :
63 next = '.'
64
65 return {'infos' : infos,
66 'isSelected' : isSelected,
67 'buyable' : buyable,
68 'backUrl' : '%s?%s' % (portfolio.absolute_url(), mq(pho_start = index/bsize*bsize)),
69 'index' : index,
70 'previous' : previous,
71 'next' : next,
72 'reBaseCtxUrl':'null',
73 'canonicalUrl':'null'}