Introduction d'un système de remise scriptable.
[Portfolio.git] / skins / getLightboxPhotosInfos.py
1 ##parameters=lightbox, pho_start=None, batch_size=None
2 from Products.CMFCore.utils import getToolByName
3 from Products.Plinn.PloneMisc import Batch
4
5 utool = getToolByName(context, 'portal_url')
6 portal = utool.getPortalObject()
7 portalDepth = len(portal.getPhysicalPath())
8 uidh = getToolByName(context, 'portal_uidhandler')
9 pptool = getToolByName(context, 'portal_photo_print', None)
10 req = context.REQUEST
11 sd = context.session_data_manager.getSessionData(create = 1)
12 path = context.getPhysicalPath()
13
14 start = pho_start if pho_start is not None else 0
15 brains = [uidh.getBrain(uid) for uid in context.uids]
16 batch_size = batch_size if batch_size is not None else context.default_batch_size
17 batch = Batch(brains, batch_size, start, quantumleap=1)
18
19 lightboxUrl = lightbox.absolute_url()
20 cart = sd.get('cart', None)
21
22 infos = []
23 for index, b in enumerate(batch) :
24 path = '/'.join(b.getPath().split('/')[portalDepth:])
25 p = b.getObject()
26 if pptool :
27 buyable = bool(pptool.getPrintingOptionsFor(p))
28 if cart and cart.locked :
29 buyable = False
30 else :
31 buyable = False
32
33 d = {'href' : '%s/lightboxcontext/%s' % (lightboxUrl, path)
34 ,'thumbUrl' : '%s/getThumbnail' % b.getURL()
35 ,'thumbSize' : b.getThumbnailSize
36 ,'title' : ('%s - %s' % (b.Title, b.Description)).strip(' -')
37 ,'cmf_uid':b.cmf_uid
38 ,'className':''
39 ,'buyable' : buyable
40 ,'o':b
41 }
42 infos.append(d)
43
44 features = {}
45 features['checkbox'] = True
46 features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL()
47
48 return {'infos' : infos,
49 'batch' : batch,
50 'features' : features}