jslint
[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
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
22 req = context.REQUEST
23 pho_start = req.get('pho_start', 0)
24 batch = Batch(portfolio.listNearestFolderContents(contentFilter={'portal_type' : ['Photo']}, sorted=True),
25 context.default_batch_size, pho_start, orphan=5, quantumleap=1, b_start_str='pho_start')
26
27
28 infos = []
29 sd = context.session_data_manager.getSessionData(create = 1)
30 selDict = sd.get('objects_selection_dict', {})
31 cart = sd.get('cart', None)
32
33 for p in batch :
34 className = ''
35 uid = getattr(p, 'cmf_uid', None)
36 if uid is not None :
37 uid = uid()
38 absUrl = p.absolute_url()
39 selected = selDict.has_key(uid)
40 hiddenForAnonymous = p.hiddenForAnonymous()
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 if selected :
49 className = 'selected'
50 if hiddenForAnonymous :
51 className = 'hidden-slide'
52
53 d = {'href' : absUrl
54 ,'thumbUrl' : '%s/getThumbnail' % absUrl
55 ,'thumbSize': p.getThumbnailSize()
56 ,'title' : ('%s - %s' % (p.Title(), p.Description())).strip(' -')
57 ,'selected' : selected
58 ,'hiddenForAnonymous' : hiddenForAnonymous
59 ,'cmf_uid' : uidtool.register(p)
60 ,'buyable' : buyable
61 ,'className': className
62 ,'o' : p
63 }
64 infos.append(d)
65
66 return {'infos':infos, 'batch':batch, 'features':features}