From: Benoît Pin Date: Fri, 22 Oct 2010 18:48:14 +0000 (+0200) Subject: Ajout du script de traitement des requêtes Lightroom. X-Git-Url: https://scm.cri.ensmp.fr/git/Portfolio.git/commitdiff_plain/ed8a0bfdc8a80311c5dee3bb668865619406021d Ajout du script de traitement des requêtes Lightroom. --- diff --git a/skins/lrservice.py b/skins/lrservice.py new file mode 100644 index 0000000..821bad1 --- /dev/null +++ b/skins/lrservice.py @@ -0,0 +1,45 @@ +##parameters= + +from Products.Plinn.utils import makeValidId +from Products.CMFCore.utils import getToolByName + +utool = getToolByName(context, 'portal_url') +portal = utool.getPortalObject() +uidtool = getToolByName(portal, 'portal_uidhandler') + +fg = context.REQUEST.form.get + +method = fg('method') + +if method == 'normaliseAndCreatePath' : + normalizedPath = [] + o = portal + path = fg('path', '').split('/') + for part in path : + validId = makeValidId(o, part, allow_dup=1) + if o.hasObject(validId) : + normalizedPath.append(validId) + o = o[validId] + else : + id = o.invokeFactory('Portfolio', validId, title=part) + o = o[id] + normalizedPath.append(id) + + return '/'.join(normalizedPath) + +elif method == 'uploadPhoto' : + path = fg('normalizedPath') + name = fg('fileName') + portfolio = portal.restrictedTraverse(path) + photoId = makeValidId(portfolio, name, allow_dup=1) + if portfolio.hasObject(photoId) : + photo = portfolio[photoId] + photo.manage_upload(fg('photo')) + else : + id = portfolio.invokeFactory('Photo', + photoId, + file=fg('photo'), + content_type='image/jpeg') + photo = portfolio[photoId] + uid = uidtool.register(photo) + return '%s %s' % (uid, photo.absolute_url())