From 393723570b65dbabd8d845d498d080c3f75272b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Thu, 28 Aug 2014 14:33:48 +0200 Subject: [PATCH] =?utf8?q?Ajout=20des=20vignettes=20apr=C3=A8s=20coup=20po?= =?utf8?q?ur=20la=20s=C3=A9lection=20courante.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- skins/getSelectionPhotosInfos.py | 65 ++++++++++++++++++++++++++++++ skins/portfolio_thumbnails_tail.py | 3 ++ skins/selection_view.py | 2 + 3 files changed, 70 insertions(+) create mode 100644 skins/getSelectionPhotosInfos.py diff --git a/skins/getSelectionPhotosInfos.py b/skins/getSelectionPhotosInfos.py new file mode 100644 index 0000000..80c52f9 --- /dev/null +++ b/skins/getSelectionPhotosInfos.py @@ -0,0 +1,65 @@ +##parameters=pho_start=None, batch_size=None +from Products.CMFCore.utils import getToolByName +from Products.Plinn.PloneMisc import Batch +from Products.Portfolio.utils import translate +def _(message) : return translate(message, context).encode('utf-8') + +uidh = getToolByName(context, 'portal_uidhandler') +utool = getToolByName(context, 'portal_url') +pptool = getToolByName(context, 'portal_photo_print', None) +portal = utool.getPortalObject() +portal_url = utool() +portalDepth = len(portal.getPhysicalPath()) +req = context.REQUEST +toUrl = req.physicalPathToURL + +# check if a lightbox is currently selected +lightboxpath = req.SESSION.get('lightboxpath', None) +selectionIsLightbox = False +if lightboxpath is None : + selection = req.SESSION.get('objects_selection', []) +else : + try : + lightbox = portal.restrictedTraverse(lightboxpath) + selection = lightbox.getUidList() + selectionIsLightbox = True + except: + req.SESSION.set('lightboxpath', None) + selection = req.SESSION.get('objects_selection', []) + + +start = pho_start if pho_start is not None else 0 +brains = [uidh.getBrain(uid) for uid in selection] +batch = Batch(brains, batch_size, start, quantumleap=1) +cart = req.SESSION.get('cart', None) + +infos = [] +for index, b in enumerate(batch) : + path = b.getPath().split('/') + path.insert(portalDepth, 'selectioncontext') + p = b.getObject() + if pptool : + buyable = bool(pptool.getPrintingOptionsFor(p)) + if cart and cart.locked : + buyable = False + else : + buyable = False + + d = {'href': toUrl('/'.join(path)) + ,'thumbUrl' : '%s/getThumbnail' % b.getURL() + ,'thumbSize' : b.getThumbnailSize + ,'title' : ('%s - %s' % (b.Title, b.Description)).strip(' -') + ,'cmf_uid':b.cmf_uid + ,'className':'' + ,'buyable' : buyable + ,'o':b + } + infos.append(d) + +features = {} +features['del'] = lambda b : '%s/remove_to_selection' % b.getURL() +features['cart'] = lambda b : '%s/get_slide_buyable_items' % b.getURL() + +return {'infos' : infos, + 'batch' : batch, + 'features' : features} \ No newline at end of file diff --git a/skins/portfolio_thumbnails_tail.py b/skins/portfolio_thumbnails_tail.py index 9765629..8e77386 100644 --- a/skins/portfolio_thumbnails_tail.py +++ b/skins/portfolio_thumbnails_tail.py @@ -8,4 +8,7 @@ elif container_type == 'lightbox' : options.update(context.getLightboxPhotosInfos(context, pho_start=start, batch_size=size)) +elif container_type == 'selection' : + options.update(context.getSelectionPhotosInfos(pho_start=start, + batch_size=size)) return context.portfolio_thumbnails_tail_template(**options) \ No newline at end of file diff --git a/skins/selection_view.py b/skins/selection_view.py index ecde5d9..aec9043 100755 --- a/skins/selection_view.py +++ b/skins/selection_view.py @@ -79,6 +79,8 @@ options = {} options['infos'] = infos options['batch'] = batch options['features'] = features + +options['container_type'] = 'selection' options['selectionIsLightbox'] = selectionIsLightbox options['breadcrumbs'] = breadcrumbs -- 2.20.1