1 | ##parameters=type_name, REQUEST=None, **kw |
---|
2 | # $Id: create_jamb.py 45 2005-10-11 12:10:17Z joachim $ |
---|
3 | """ |
---|
4 | Create an object. |
---|
5 | |
---|
6 | FIXME: what are the parameters? |
---|
7 | """ |
---|
8 | |
---|
9 | from urllib import urlencode |
---|
10 | |
---|
11 | if REQUEST is not None: |
---|
12 | kw.update(REQUEST.form) |
---|
13 | # Use creation without empty object. |
---|
14 | # XXX should find better |
---|
15 | ti = getattr(context.portal_types, type_name) |
---|
16 | # For cpsdocument |
---|
17 | if ti.meta_type == 'CPS Flexible Type Information': |
---|
18 | args = {'type_name': type_name} |
---|
19 | # XXX pass prefilled title, a bit of a hack... |
---|
20 | args['widget__Title'] = kw.get('title', '') |
---|
21 | |
---|
22 | # Look for the create action on the ti |
---|
23 | create_action_form = ti.getActionById('create', 'cpsdocument_create_form') |
---|
24 | |
---|
25 | return REQUEST.RESPONSE.redirect('%s/%s?%s' |
---|
26 | % (context.absolute_url(), |
---|
27 | create_action_form, |
---|
28 | urlencode(args))) |
---|
29 | |
---|
30 | if REQUEST and not kw.get('title'): |
---|
31 | # Need a title before creating folders |
---|
32 | if type_name in ('Section', 'Workspace'): |
---|
33 | args = {'type_name': type_name} |
---|
34 | return REQUEST.RESPONSE.redirect('%s/folder_edit_form?%s' % |
---|
35 | (context.absolute_url(), urlencode(args))) |
---|
36 | |
---|
37 | id = kw.get('title', 'my_' + type_name) |
---|
38 | id = context.computeId(compute_from=id) |
---|
39 | |
---|
40 | context.invokeFactory(type_name, id) |
---|
41 | ob = getattr(context, id) |
---|
42 | |
---|
43 | try: |
---|
44 | doc = ob.getEditableContent() |
---|
45 | except AttributeError: |
---|
46 | # not a proxy |
---|
47 | doc = ob |
---|
48 | else: |
---|
49 | try: |
---|
50 | doc.edit(proxy=ob, **kw) |
---|
51 | except: |
---|
52 | # CMF Compatibility. |
---|
53 | # type_name not necessarly and edit method |
---|
54 | # for CMF types is not aware about that. |
---|
55 | if kw.has_key('type_name'): |
---|
56 | del kw['type_name'] |
---|
57 | doc.edit(**kw) |
---|
58 | |
---|
59 | context.portal_eventservice.notifyEvent('modify_object', context, {}) |
---|
60 | context.portal_eventservice.notifyEvent('modify_object', ob, {}) |
---|
61 | |
---|
62 | |
---|
63 | if REQUEST is not None: |
---|
64 | psm = 'psm_content_created' |
---|
65 | action_path = doc.getTypeInfo().immediate_view # getActionById('metadata') |
---|
66 | REQUEST.RESPONSE.redirect('%s/%s?portal_status_message=%s' % |
---|
67 | (ob.absolute_url(), action_path, |
---|
68 | psm)) |
---|
69 | |
---|
70 | return id |
---|