2d42635bcf238789c1fa9daacad26afd9524236f
[Portfolio.git] / skins / getPhotosInfos.py
1 ##parameters=portfolio
2 from Products.Plinn.PloneMisc import Batch
3 from Products.CMFCore.utils import getToolByName
4 from Products.CMFCore.permissions import ReviewPortalContent, ModifyPortalContent
5 mtool = getToolByName(context, 'portal_membership')
6 pptool = getToolByName(context, 'portal_photo_print', None)
7 uidtool = getToolByName(context, 'portal_uidhandler')
8
9 features = {}
10 def toggleSelection(o, selected) :
11 if selected :
12 return '%s/remove_to_selection' % o.absolute_url()
13 else :
14 return '%s/add_to_selection' % o.absolute_url()
15
16 features['select'] = toggleSelection
17 features['cart'] = lambda o : '%s/get_slide_buyable_items' % o.absolute_url()
18
19 if mtool.checkPermission(ReviewPortalContent, context) :
20 features['hideAnonymous'] = True
21 if mtool.checkPermission(ModifyPortalContent, context) :
22 features['checkbox'] = True
23
24 req = context.REQUEST
25 pho_start = req.get('pho_start', 0)
26 batch = Batch(portfolio.listNearestFolderContents(contentFilter={'portal_type' : ['Photo']}, sorted=True),
27 context.default_batch_size, pho_start, orphan=5, quantumleap=1, b_start_str='pho_start')
28
29
30 infos = []
31 sd = context.session_data_manager.getSessionData(create = 1)
32 selDict = sd.get('objects_selection_dict', {})
33 cart = sd.get('cart', None)
34
35 for p in batch :
36 className = ''
37 uid = getattr(p, 'cmf_uid', None)
38 if uid is not None :
39 uid = uid()
40 absUrl = p.absolute_url()
41 selected = selDict.has_key(uid)
42 hiddenForAnonymous = p.hiddenForAnonymous()
43 if pptool :
44 buyable = bool(pptool.getPrintingOptionsFor(p))
45 if cart and cart.locked :
46 buyable = False
47 else :
48 buyable = False
49
50 if selected :
51 className = 'selected'
52 if hiddenForAnonymous :
53 className = 'hidden-slide'
54
55 d = {'href' : absUrl
56 ,'thumbUrl' : '%s/getThumbnail' % absUrl
57 ,'thumbSize': p.getThumbnailSize()
58 ,'title' : ('%s - %s' % (p.Title(), p.Description())).strip(' -')
59 ,'selected' : selected
60 ,'hiddenForAnonymous' : hiddenForAnonymous
61 ,'cmf_uid' : uidtool.register(p)
62 ,'buyable' : buyable
63 ,'className': className
64 ,'o' : p
65 }
66 infos.append(d)
67
68 return {'infos':infos, 'batch':batch, 'features':features}