root/CPS3/products/CPSDocument/trunk/skins/cps_document/cpsdocument_create.py

Revision 51961, 1.6 kB (checked in by madarche, 3 years ago)

Related to #1827 : made the mechanism that newly created documents in a workspace
should become the first document in this workspace stronger by only trying to
apply it on ordered containers, that is not on BTrees for example.


  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 ##parameters=REQUEST, cluster=None, type_name=None
2 # $Id$
3 """
4 Called when a document form is posted.
5
6 Validates data, then:
7
8  - if there's no error, updates the object and redirects to it,
9
10  - if there's an error, puts data in session and redirects to creation form.
11
12 A form uid is propagated during the redirect to uniquely identify the
13 form in the session.
14 """
15 from urllib import urlencode
16 from Products.CMFCore.utils import getToolByName
17 from Products.CPSDefault.utils import isIOrderedContainer
18 from Products.CPSDocument.utils import getFormUidUrlArg
19
20 ti = getToolByName(context, 'portal_types').getTypeInfo(type_name)
21
22 is_valid, ds = ti.validateObject(None, layout_mode='create',
23                                  request=REQUEST, context=context,
24                                  cluster=cluster, use_session=True)
25
26 if is_valid:
27     meth_id = ti.queryMethodID('create_do', 'cpsdocument_create_do')
28     ob = getattr(context, meth_id)(type_name, ds.getDataModel())
29     url = ob.absolute_url()
30     action = ob.getTypeInfo().immediate_view
31     psm = 'psm_content_created'
32     args = {}
33     # Move the newly created object as the first object in the folder,
34     # otherwise in folders with more that one page of documents
35     # one would have to go to the last page.
36     if isIOrderedContainer(context):
37         context.moveObjectsToTop([ob.getId()])
38 else:
39     url = context.absolute_url()
40     action = 'cpsdocument_create_form'
41     psm = 'psm_content_error'
42     args = {'type_name': type_name}
43     args.update(getFormUidUrlArg(REQUEST))
44
45 args['portal_status_message'] = psm
46 url = url + '/' + action + '?' + urlencode(args)
47 REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the browser.