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