Insertion sélection après la cible.
[Portfolio.git] / skins / getPhotosInfos.py
1 ##parameters=portfolio, pho_start=None, batch_size=None
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.getURL()
13 else :
14 return '%s/add_to_selection' % o.getURL()
15
16 features['select'] = toggleSelection
17 features['cart'] = lambda o : '%s/get_slide_buyable_items' % o.getURL()
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 = pho_start if pho_start is not None else 0
26 batch_size = batch_size if batch_size is not None else context.default_batch_size
27 sort_on, sort_order = context.getDefaultSorting()
28 contentFilter = {'portal_type' : ['Photo'],
29 'sort_on' : sort_on,
30 'sort_order' : sort_order}
31 batch = Batch(portfolio.listCatalogedContents(contentFilter=contentFilter),
32 batch_size, pho_start, quantumleap=1, b_start_str='pho_start')
33
34
35 infos = []
36 sd = context.session_data_manager.getSessionData(create = 1)
37 selDict = sd.get('objects_selection_dict', {})
38 cart = sd.get('cart', None)
39
40 for p in batch :
41 className = ''
42 uid = getattr(p, 'cmf_uid', None)
43 # if uid is not None :
44 # uid = uid()
45 absUrl = p.getURL()
46 selected = selDict.has_key(uid)
47 hiddenForAnonymous = p.hiddenForAnonymous
48 if pptool :
49 buyable = bool(pptool.getPrintingOptionsFor(p.getObject()))
50 if cart and cart.locked :
51 buyable = False
52 else :
53 buyable = False
54
55 if selected :
56 className = 'selected'
57 if hiddenForAnonymous :
58 className = 'hidden-slide'
59
60 d = {'href' : absUrl
61 ,'thumbUrl' : '%s/getThumbnail' % absUrl
62 ,'thumbSize': p.getThumbnailSize
63 ,'title' : ('%s - %s' % (p.Title, p.Description)).strip(' -')
64 ,'selected' : selected
65 ,'hiddenForAnonymous' : hiddenForAnonymous
66 ,'cmf_uid' : uidtool.register(p)
67 ,'buyable' : buyable
68 ,'className': className
69 ,'o' : p
70 }
71 infos.append(d)
72
73 return {'infos':infos,
74 'batch':batch,
75 'features':features,
76 'sorting' : {'sort_on' : sort_on,
77 'sort_order' : sort_order}
78 }