Début d'implémentation du rafraîchissement des images après modification du tri.
[Portfolio.git] / skins / lrservice.py
1 ##parameters=
2
3 from Products.Plinn.utils import makeValidId
4 from Products.CMFCore.utils import getToolByName
5
6 utool = getToolByName(context, 'portal_url')
7 portal = utool.getPortalObject()
8 uidtool = getToolByName(portal, 'portal_uidhandler')
9
10 fg = context.REQUEST.form.get
11
12 method = fg('method')
13
14 if method == 'normaliseAndCreatePath' :
15 normalizedPath, uids = [], []
16 o = portal
17 path = fg('path', '').split(' ') # séparateur : 0x09 (tabulation)
18 for part in path :
19 validId = makeValidId(o, part, allow_dup=1)
20 if o.hasObject(validId) :
21 normalizedPath.append(validId)
22 o = o[validId]
23 else :
24 id = o.invokeFactory('Portfolio', validId, title=part)
25 o = o[id]
26 normalizedPath.append(id)
27 uid = uidtool.register(o)
28 uids.append(uid)
29
30 return '%s\n%s' % ('/'.join(normalizedPath), ' '.join([str(uid) for uid in uids]))
31
32 elif method == 'uploadPhoto' :
33 path = fg('normalizedPath')
34 name = fg('fileName')
35 portfolio = portal.restrictedTraverse(path)
36 photoId = makeValidId(portfolio, name, allow_dup=1)
37 if portfolio.hasObject(photoId) :
38 photo = portfolio[photoId]
39 photo.manage_upload(fg('photo'))
40 else :
41 id = portfolio.invokeFactory('Photo',
42 photoId,
43 file=fg('photo'),
44 content_type='image/jpeg')
45 photo = portfolio[photoId]
46 uid = uidtool.register(photo)
47 return '%s %s' % (uid, photo.absolute_url())
48
49 elif method in ('deletePhoto', 'deletePortfolio') :
50 o = uidtool.queryObject(fg('uid'))
51 if o :
52 parent = o.getParentNode()
53 parent.manage_delObjects([o.getId()])