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