Callback ajax après déplacement.
[Portfolio.git] / skins / getSelectionPhotosInfos.py
1 ##parameters=pho_start=None, batch_size=None
2 from Products.CMFCore.utils import getToolByName
3 from Products.Plinn.PloneMisc import Batch
4
5 uidh = getToolByName(context, 'portal_uidhandler')
6 utool = getToolByName(context, 'portal_url')
7 pptool = getToolByName(context, 'portal_photo_print', None)
8 portal = utool.getPortalObject()
9 portal_url = utool()
10 portalDepth = len(portal.getPhysicalPath())
11 req = context.REQUEST
12 toUrl = req.physicalPathToURL
13
14 # check if a lightbox is currently selected
15 lightboxpath = req.SESSION.get('lightboxpath', None)
16 selectionIsLightbox = False
17 if lightboxpath is None :
18 selection = req.SESSION.get('objects_selection', [])
19 else :
20 try :
21 lightbox = portal.restrictedTraverse(lightboxpath)
22 selection = lightbox.getUidList()
23 selectionIsLightbox = True
24 except:
25 req.SESSION.set('lightboxpath', None)
26 selection = req.SESSION.get('objects_selection', [])
27
28
29 brains = [uidh.getBrain(uid) for uid in selection]
30 start = pho_start if pho_start is not None else 0
31 batch_size = batch_size if batch_size is not None else context.default_batch_size
32 batch = Batch(brains, batch_size, start, quantumleap=1)
33 cart = req.SESSION.get('cart', None)
34
35 infos = []
36 for index, b in enumerate(batch) :
37 path = b.getPath().split('/')
38 path.insert(portalDepth, 'selectioncontext')
39 p = b.getObject()
40 if pptool :
41 buyable = bool(pptool.getPrintingOptionsFor(p))
42 if cart and cart.locked :
43 buyable = False
44 else :
45 buyable = False
46
47 d = {'href': toUrl('/'.join(path))
48 ,'thumbUrl' : '%s/getThumbnail' % b.getURL()
49 ,'thumbSize' : b.getThumbnailSize
50 ,'title' : ('%s - %s' % (b.Title, b.Description)).strip(' -')
51 ,'cmf_uid':b.cmf_uid
52 ,'className':''
53 ,'buyable' : buyable
54 ,'o':b
55 }
56 infos.append(d)
57
58 features = {}
59 features['checkbox'] = True
60 features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL()
61
62 return {'infos' : infos,
63 'batch' : batch,
64 'features' : features}