Ajout du script de traitement des requêtes Lightroom.
authorBenoît Pin <benoit.pin@gmail.com>
Fri, 22 Oct 2010 18:48:14 +0000 (20:48 +0200)
committerBenoît Pin <benoit.pin@gmail.com>
Fri, 22 Oct 2010 18:48:14 +0000 (20:48 +0200)
skins/lrservice.py [new file with mode: 0644]

diff --git a/skins/lrservice.py b/skins/lrservice.py
new file mode 100644 (file)
index 0000000..821bad1
--- /dev/null
@@ -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())