## Script (Python) "cpsdocument_create" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=REQUEST, cluster=None, type_name=None ##title= ## # $Id: cpsdocument_create.py 486 2006-09-06 10:09:39Z joachim $ """ Called when a document form is posted. Validates data, then: - if there's no error, updates the object and redirects to it, - if there's an error, puts data in session and redirects to creation form. A form uid is propagated during the redirect to uniquely identify the form in the session. """ from urllib import urlencode from Products.CMFCore.utils import getToolByName from Products.CPSDocument.utils import getFormUidUrlArg ti = getToolByName(context, 'portal_types').getTypeInfo(type_name) while True: if not context.isSectionOfficer(): psm = "illegal access" break is_valid, ds = ti.validateObject(None, layout_mode='create', request=REQUEST, context=context, cluster=cluster, use_session=True) if is_valid: meth_id = ti.queryMethodID('create_do', 'cpsdocument_create_do') ob = getattr(context, meth_id)(type_name, ds.getDataModel()) url = ob.absolute_url() meth_id = ti.queryMethodID('created', None) if meth_id is not None: getattr(context, meth_id)(object=ob) action = ob.getTypeInfo().immediate_view psm = 'psm_content_created' args = {} else: url = context.absolute_url() action = 'cpsdocument_create_form' psm = 'psm_content_error' args = {'type_name': type_name} args.update(getFormUidUrlArg(REQUEST)) break args['portal_status_message'] = psm url = url + '/' + action + '?' + urlencode(args) REQUEST.RESPONSE.redirect(url)