Avancement du refactoring.
[Portfolio.git] / skins / getPhotoInfo.py
1 ##parameters=
2 from Products.CMFCore.utils import getToolByName
3 from Products.CMFCore.permissions import ReviewPortalContent
4 mtool = getToolByName(context, 'portal_membership')
5 pptool = getToolByName(context, 'portal_photo_print', None)
6 uidtool = getToolByName(context, 'portal_uidhandler')
7
8 features = {}
9 def toggleSelection(o, selected) :
10 if selected :
11 return '%s/remove_to_selection' % o.absolute_url()
12 else :
13 return '%s/add_to_selection' % o.absolute_url()
14
15 features['select'] = toggleSelection
16 features['cart'] = lambda o : '%s/get_slide_buyable_items' % o.absolute_url()
17
18 if mtool.checkPermission(ReviewPortalContent, context) :
19 features['hideAnonymous'] = True
20
21 sd = context.session_data_manager.getSessionData(create = 1)
22 selDict = sd.get('objects_selection_dict', {})
23 cart = sd.get('cart', None)
24
25 p = context
26 className = ''
27 uid = getattr(p, 'cmf_uid', None)
28 if uid is not None :
29 uid = uid()
30 absUrl = p.absolute_url()
31 selected = selDict.has_key(uid)
32 hiddenForAnonymous = p.hiddenForAnonymous()
33 if pptool :
34 buyable = bool(pptool.getPrintingOptionsFor(p))
35 if cart and cart.locked :
36 buyable = False
37 else :
38 buyable = False
39
40 if selected :
41 className = 'selected'
42 if hiddenForAnonymous :
43 className = 'hidden-slide'
44
45 d = {'href' : absUrl
46 ,'thumbUrl' : '%s/getThumbnail' % absUrl
47 ,'thumbSize': p.getThumbnailSize()
48 ,'title' : ('%s - %s' % (p.Title(), p.Description())).strip(' -')
49 ,'selected' : selected
50 ,'hiddenForAnonymous' : hiddenForAnonymous
51 ,'cmf_uid' : uidtool.register(p)
52 ,'buyable' : buyable
53 ,'className': className
54 ,'o' : p
55 }
56
57 return {'info' : d, 'features' : features}