source: waeup_product/trunk/skins/waeup_student/create_jamb.py @ 47

Last change on this file since 47 was 45, checked in by joachim, 19 years ago

major rewrite

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1##parameters=type_name, REQUEST=None, **kw
2# $Id: create_jamb.py 45 2005-10-11 12:10:17Z joachim $
3"""
4Create an object.
5
6FIXME: what are the parameters?
7"""
8
9from urllib import urlencode
10
11if 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
30if 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
37id = kw.get('title', 'my_' + type_name)
38id = context.computeId(compute_from=id)
39
40context.invokeFactory(type_name, id)
41ob = getattr(context, id)
42
43try:
44    doc = ob.getEditableContent()
45except AttributeError:
46    # not a proxy
47    doc = ob
48else:
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
59context.portal_eventservice.notifyEvent('modify_object', context, {})
60context.portal_eventservice.notifyEvent('modify_object', ob, {})
61
62
63if 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
70return id
Note: See TracBrowser for help on using the repository browser.