source: waeup_product/trunk/skins/waeup_student/create_student.py @ 146

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

major rewrite

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1##parameters=type_name, REQUEST=None, **kw
2# $Id: create_student.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
11##for k,v in kw.items():
12##    print k,v
13##return printed
14
15if 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
35if 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
43id = kw.get('title', 'my_sdfsdfdsf' + type_name)
44id = context.computeId(compute_from=id)
45
46context.invokeFactory(type_name, id)
47ob = getattr(context, id)
48
49try:
50    doc = ob.getEditableContent()
51except AttributeError:
52    # not a proxy
53    doc = ob
54else:
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
65context.portal_eventservice.notifyEvent('modify_object', context, {})
66context.portal_eventservice.notifyEvent('modify_object', ob, {})
67
68
69if 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
76return id
Note: See TracBrowser for help on using the repository browser.