3 from Products
.Plinn
.utils
import makeValidId
4 from Products
.CMFCore
.utils
import getToolByName
6 utool
= getToolByName(context
, 'portal_url')
7 portal
= utool
.getPortalObject()
8 uidtool
= getToolByName(portal
, 'portal_uidhandler')
10 fg
= context
.REQUEST
.form
.get
14 if method
== 'normaliseAndCreatePath' :
17 path
= fg('path', '').split('/')
19 validId
= makeValidId(o
, part
, allow_dup
=1)
20 if o
.hasObject(validId
) :
21 normalizedPath
.append(validId
)
24 id = o
.invokeFactory('Portfolio', validId
, title
=part
)
26 normalizedPath
.append(id)
28 return '/'.join(normalizedPath
)
30 elif method
== 'uploadPhoto' :
31 path
= fg('normalizedPath')
33 portfolio
= portal
.restrictedTraverse(path
)
34 photoId
= makeValidId(portfolio
, name
, allow_dup
=1)
35 if portfolio
.hasObject(photoId
) :
36 photo
= portfolio
[photoId
]
37 photo
.manage_upload(fg('photo'))
39 id = portfolio
.invokeFactory('Photo',
42 content_type
='image/jpeg')
43 photo
= portfolio
[photoId
]
44 uid
= uidtool
.register(photo
)
45 return '%s %s' % (uid
, photo
.absolute_url())