Initialisation du Content-Type à text/xml.
[Portfolio.git] / skins / lightbox_view.py
1 ##parameters=load='',unload='',**kw
2 from Products.CMFCore.utils import getToolByName
3 from Products.Plinn.PloneMisc import Batch
4 options = {}
5 buttons = []
6 lightboxSelected = False
7
8 utool = getToolByName(context, 'portal_url')
9 portal = utool.getPortalObject()
10 portalDepth = len(portal.getPhysicalPath())
11 uidh = getToolByName(context, 'portal_uidhandler')
12 pptool = getToolByName(context, 'portal_photo_print', None)
13 req = context.REQUEST
14 sd = context.session_data_manager.getSessionData(create = 1)
15 path = context.getPhysicalPath()
16
17 if load :
18 sd.set('lightboxpath', path)
19 selection = context.getUidList()
20 sd.set('objects_selection', selection)
21 sd.set('objects_selection_dict', dict([(uid, True) for uid in selection]))
22 elif unload :
23 sd.set('lightboxpath', None)
24 sd.set('objects_selection', [])
25 sd.set('objects_selection_dict', {})
26
27 sessionpath = sd.get('lightboxpath', None)
28 if sessionpath == path :
29 lightboxSelected = True
30 buttons.append({'name': 'unload', 'value': 'Unload from my selection'})
31 else :
32 buttons.append({'name':'load', 'value': 'Load in my selection'})
33
34 start = req.get('b_start', 0)
35 brains = [uidh.getBrain(uid) for uid in context.uids]
36 batch = Batch(brains, context.default_batch_size, start, orphan=1, quantumleap=1)
37
38 hereUrl = context.absolute_url()
39 cart = sd.get('cart', None)
40
41 infos = []
42 for index, b in enumerate(batch) :
43 path = '/'.join(b.getPath().split('/')[portalDepth:])
44 p = b.getObject()
45 if pptool :
46 buyable = bool(pptool.getPrintingOptionsFor(p))
47 if cart and cart.locked :
48 buyable = False
49 else :
50 buyable = False
51
52 d = {'href' : '%s/lightboxcontext/%s' % (hereUrl, path)
53 ,'thumbUrl' : '%s/getThumbnail' % b.getURL()
54 ,'thumbSize' : b.getThumbnailSize
55 ,'title' : ('%s - %s' % (b.Title, b.Description)).strip(' -')
56 ,'cmf_uid':b.cmf_uid
57 ,'className':''
58 ,'buyable' : buyable
59 ,'o':b
60 }
61 infos.append(d)
62
63 features = {}
64 features['del'] = lambda b: '%s/remove_to_lightbox?uid=%s' % (hereUrl, b.cmf_uid)
65 features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL()
66
67 options['infos'] = infos
68 options['batch'] = batch
69 options['features'] = features
70 options['buttons'] = buttons
71 options['lightboxSelected'] = lightboxSelected
72
73 return context.lightbox_view_template(**options)