Upload avec script adhoc.
[Portfolio.git] / skins / selection_view.py
1 ##parameters=
2 from Products.CMFCore.utils import getToolByName
3 from Products.Plinn.PloneMisc import Batch
4 from Products.Portfolio.utils import translate
5 def _(message) : return translate(message, context).encode('utf-8')
6
7 uidh = getToolByName(context, 'portal_uidhandler')
8 utool = getToolByName(context, 'portal_url')
9 pptool = getToolByName(context, 'portal_photo_print', None)
10 portal = utool.getPortalObject()
11 portal_url = utool()
12 portalDepth = len(portal.getPhysicalPath())
13 req = context.REQUEST
14 toUrl = req.physicalPathToURL
15
16 # check if a lightbox is currently selected
17 lightboxpath = req.SESSION.get('lightboxpath', None)
18 selectionIsLightbox = False
19 if lightboxpath is None :
20 selection = req.SESSION.get('objects_selection', [])
21 else :
22 try :
23 lightbox = portal.restrictedTraverse(lightboxpath)
24 selection = lightbox.getUidList()
25 selectionIsLightbox = True
26 except:
27 req.SESSION.set('lightboxpath', None)
28 selection = req.SESSION.get('objects_selection', [])
29
30 start = req.get('b_start', 0)
31 brains = [uidh.getBrain(uid) for uid in selection]
32 batch = Batch(brains, context.default_batch_size, start, orphan=1, quantumleap=1)#, b_start_str='pho_start')
33 cart = req.SESSION.get('cart', None)
34
35 infos = []
36 for index, b in enumerate(batch) :
37 path = b.getPath().split('/')
38 path.insert(portalDepth, 'selectioncontext')
39 p = b.getObject()
40 if pptool :
41 buyable = bool(pptool.getPrintingOptionsFor(p))
42 if cart and cart.locked :
43 buyable = False
44 else :
45 buyable = False
46
47 d = {'href': toUrl('/'.join(path))
48 ,'thumbUrl' : '%s/getThumbnail' % b.getURL()
49 ,'thumbSize' : b.getThumbnailSize
50 ,'title' : ('%s - %s' % (b.Title, b.Description)).strip(' -')
51 ,'cmf_uid':b.cmf_uid
52 ,'className':''
53 ,'buyable' : buyable
54 ,'o':b
55 }
56 infos.append(d)
57
58 features = {}
59 features['del'] = lambda b : '%s/remove_to_selection' % b.getURL()
60 features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL()
61
62 # breadcrumbs customization
63 if selectionIsLightbox :
64 lastBcTitle = '%s (%s)' % (_('My selection'), lightbox.title_or_id())
65 else :
66 lastBcTitle = _('My selection')
67 breadcrumbs = [
68 { 'id' : 'root'
69 , 'title' : portal.title
70 , 'url' : portal_url},
71
72 {'id' : 'selection_view'
73 ,'title' : lastBcTitle
74 , 'url' : '%s/selection_view' % portal_url}
75 ]
76
77
78 options = {}
79 options['infos'] = infos
80 options['batch'] = batch
81 options['features'] = features
82 options['selectionIsLightbox'] = selectionIsLightbox
83 options['breadcrumbs'] = breadcrumbs
84
85 if selectionIsLightbox :
86 options['lightbox'] = lightbox
87 else :
88 options['selectionName'] = 'not saved yet'
89
90 return context.selection_view_template(**options)