Un identificateur unique est automatiquement donné à la création d'un objet.
[Plinn.git] / skins / control / add_content.py
1 ##parameters=
2 from Products.Plinn.utils import makeValidId
3 form = context.REQUEST.form
4 from Products.CMFCore.utils import getToolByName
5 handler = getToolByName(context, 'portal_uidhandler')
6
7 for k in form.keys() :
8 item = form[k]
9 if hasattr(item, 'keys') and item.has_key('type') :
10 typeDic = item.copy()
11 typeDic['type'] = k
12 break
13
14 if typeDic.has_key('id') :
15 title = typeDic['id']
16 newid = makeValidId(context, title)
17
18 context.invokeFactory( typeDic['type'], newid, title=title)
19 newOb = getattr(context, newid)
20 handler = getToolByName(context, 'portal_uidhandler')
21 handler.register(newOb)
22 ti = newOb.getTypeInfo()
23 immediate_view = ti.immediate_view
24
25 if immediate_view.find('/') > 0 :
26 newOb.setStatus('True', 'Object created.')
27 return newOb.setRedirect(newOb, immediate_view, syncFragments = ['Breadcrumbs', 'rightCell'], **form)
28 else :
29 from ZTUtils import make_query
30 ob_url = newOb.absolute_url()
31 query = make_query(portal_status_message = 'Object created.', ajax = form.get('ajax'), syncFragments = ['Breadcrumbs', 'rightCell'])
32 url = "%s/%s?%s" % (ob_url, immediate_view, query)
33 response = context.REQUEST.RESPONSE
34 return response.redirect(url)
35
36 elif typeDic.has_key('create_form') :
37 from Products.CMFCore.utils import getToolByName
38 ttool = getToolByName(context, 'portal_types')
39 typeName = typeDic['type']
40 ti = getattr(ttool, typeName)
41 ai = ti.getActionInfo('object/create', object=context)
42 url = ai['url']
43
44 from ZTUtils import make_query
45 query = make_query(ajax=form.get('ajax'))
46 url = '%s?%s' % (url, query)
47 response = context.REQUEST.RESPONSE
48 return response.redirect(url)