[2217] | 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 | """ |
---|
| 12 | Called when a document form is posted. |
---|
| 13 | |
---|
| 14 | Validates 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 | |
---|
| 20 | A form uid is propagated during the redirect to uniquely identify the |
---|
| 21 | form in the session. |
---|
| 22 | """ |
---|
| 23 | from urllib import urlencode |
---|
| 24 | from Products.CMFCore.utils import getToolByName |
---|
| 25 | from Products.CPSDocument.utils import getFormUidUrlArg |
---|
| 26 | |
---|
[3824] | 27 | request = REQUEST |
---|
| 28 | |
---|
| 29 | try: |
---|
| 30 | from Products.zdb import set_trace |
---|
| 31 | except: |
---|
| 32 | def set_trace(): |
---|
| 33 | pass |
---|
| 34 | |
---|
[2217] | 35 | ti = getToolByName(context, 'portal_types').getTypeInfo(type_name) |
---|
| 36 | |
---|
[3157] | 37 | while True: |
---|
| 38 | if not context.isSectionOfficer(): |
---|
[3824] | 39 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 40 | |
---|
[3157] | 41 | is_valid, ds = ti.validateObject(None, layout_mode='create', |
---|
| 42 | request=REQUEST, context=context, |
---|
| 43 | cluster=cluster, use_session=True) |
---|
| 44 | |
---|
| 45 | if is_valid: |
---|
| 46 | meth_id = ti.queryMethodID('create_do', 'cpsdocument_create_do') |
---|
| 47 | ob = getattr(context, meth_id)(type_name, ds.getDataModel()) |
---|
| 48 | url = ob.absolute_url() |
---|
| 49 | meth_id = ti.queryMethodID('created', None) |
---|
| 50 | if meth_id is not None: |
---|
| 51 | getattr(context, meth_id)(object=ob) |
---|
| 52 | action = ob.getTypeInfo().immediate_view |
---|
| 53 | psm = 'psm_content_created' |
---|
| 54 | args = {} |
---|
| 55 | else: |
---|
| 56 | url = context.absolute_url() |
---|
| 57 | action = 'cpsdocument_create_form' |
---|
| 58 | psm = 'psm_content_error' |
---|
| 59 | args = {'type_name': type_name} |
---|
| 60 | args.update(getFormUidUrlArg(REQUEST)) |
---|
| 61 | break |
---|
| 62 | |
---|
[2217] | 63 | args['portal_status_message'] = psm |
---|
| 64 | url = url + '/' + action + '?' + urlencode(args) |
---|
| 65 | REQUEST.RESPONSE.redirect(url) |
---|