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