bugfix : XMLHttpRequest.status est un entier.
[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 form = context.REQUEST.form
7 portfolio = context.getParentNode()
8 bsize = form.get('b_size',20)
9
10 infos = []
11 index = 0
12 sd = context.session_data_manager.getSessionData(create = 1)
13 selDict = sd.get('objects_selection_dict', {})
14 cart = sd.get('cart', None)
15
16 contextUid = getattr(context, 'cmf_uid', None)
17 if contextUid is not None :
18 contextUid = contextUid()
19 else :
20 uidh = getToolByName(context, 'portal_uidhandler')
21 contextUid = uidtool.register(context)
22 isSelected = selDict.has_key(contextUid)
23
24 for i, p in enumerate(portfolio.listNearestFolderContents(contentFilter={'portal_type' : ['Photo']}, sorted=True)) :
25 if not p.size :
26 continue
27 uid = getattr(p, 'cmf_uid', None)
28 if uid is not None :
29 uid = uid()
30 selected = selDict.has_key(uid)
31 size = p.getThumbnailSize()
32 size = {'width':int(size['width']/2.0), 'height':int(size['height']/2.0)}
33 purl = p.absolute_url()
34 d = {'src': '%s/getThumbnail' % purl
35 ,'href': purl
36 ,'thumbSize':size
37 ,'title' : p.Title()
38 ,'className': (selected and 'selected' or '') + ((p == context) and ' displayed' or '')
39 , 'index': i
40 }
41 if contextUid == uid:
42 index = i
43
44 infos.append(d)
45
46 if pptool :
47 buyable = bool(pptool.getPrintingOptionsFor(context))
48 if cart and cart.locked :
49 buyable = False
50 else :
51 buyable = False
52
53 if index > 0 :
54 previous = infos[index - 1]['href']
55 else :
56 previous = '.'
57
58 if index < len(infos) -1 :
59 next = infos[index + 1]['href']
60 else :
61 next = '.'
62
63 return {'infos' : infos,
64 'isSelected' : isSelected,
65 'buyable' : buyable,
66 'backUrl' : '%s?%s' % (portfolio.absolute_url(), mq(pho_start = index/bsize*bsize)),
67 'index' : index,
68 'previous' : previous,
69 'next' : next,
70 'reBaseCtxUrl':'null',
71 'canonicalUrl':'null'}