source: WAeUP_SRP/trunk/skins/cps_custom/cpsdocument_create.py @ 3778

Last change on this file since 3778 was 3157, checked in by joachim, 17 years ago

allow cpsdocument_create only for section_officers

File size: 1.8 KB
Line 
1## Script (Python) "cpsdocument_create"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=REQUEST, cluster=None, type_name=None
8##title=
9##
10# $Id: cpsdocument_create.py 486 2006-09-06 10:09:39Z joachim $
11"""
12Called when a document form is posted.
13
14Validates data, then:
15
16 - if there's no error, updates the object and redirects to it,
17
18 - if there's an error, puts data in session and redirects to creation form.
19
20A form uid is propagated during the redirect to uniquely identify the
21form in the session.
22"""
23from urllib import urlencode
24from Products.CMFCore.utils import getToolByName
25from Products.CPSDocument.utils import getFormUidUrlArg
26
27ti = getToolByName(context, 'portal_types').getTypeInfo(type_name)
28
29while True:
30    if not context.isSectionOfficer():
31        psm = "illegal access"
32        break
33    is_valid, ds = ti.validateObject(None, layout_mode='create',
34                                    request=REQUEST, context=context,
35                                    cluster=cluster, use_session=True)
36   
37    if is_valid:
38        meth_id = ti.queryMethodID('create_do', 'cpsdocument_create_do')
39        ob = getattr(context, meth_id)(type_name, ds.getDataModel())
40        url = ob.absolute_url()
41        meth_id = ti.queryMethodID('created', None)
42        if meth_id is not None:
43            getattr(context, meth_id)(object=ob)
44        action = ob.getTypeInfo().immediate_view
45        psm = 'psm_content_created'
46        args = {}
47    else:
48        url = context.absolute_url()
49        action = 'cpsdocument_create_form'
50        psm = 'psm_content_error'
51        args = {'type_name': type_name}
52        args.update(getFormUidUrlArg(REQUEST))
53    break
54   
55args['portal_status_message'] = psm
56url = url + '/' + action + '?' + urlencode(args)
57REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.