b070a83093930a8e8d1d79d8e1361400035cac7c
[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 ,'displayed' : p == context
41 ,'className': (selected and 'selected' or '') + ((p == context) and ' displayed' or '')
42 , 'index': i
43 }
44 if contextUid == uid:
45 index = i
46
47 infos.append(d)
48
49 if pptool :
50 buyable = bool(pptool.getPrintingOptionsFor(context))
51 if cart and cart.locked :
52 buyable = False
53 else :
54 buyable = False
55
56 if index > 0 :
57 previous = infos[index - 1]['href']
58 else :
59 previous = '.'
60
61 if index < len(infos) -1 :
62 next = infos[index + 1]['href']
63 else :
64 next = '.'
65
66 return {'infos' : infos,
67 'isSelected' : isSelected,
68 'buyable' : buyable,
69 'backUrl' : '%s?%s' % (portfolio.absolute_url(), mq(pho_start = index/bsize*bsize)),
70 'index' : index,
71 'previous' : previous,
72 'next' : next,
73 'reBaseCtxUrl':'null',
74 'canonicalUrl':'null'}