source: products/qPloneCaptchaField/trunk/skins/qplonecaptchafield/createObject.cpy @ 3665

Last change on this file since 3665 was 263, checked in by fenix, 18 years ago

create tags for qPloneEpydoc

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1## Controller Python Script "createObject"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind state=state
7##bind subpath=traverse_subpath
8##parameters=id=None,type_name=None,script_id=None
9##title=
10##
11
12from DateTime import DateTime
13from Products.CMFPlone.utils import transaction_note
14from Products.CMFPlone import PloneMessageFactory as _
15from Products.CMFCore.utils import getToolByName
16REQUEST=context.REQUEST
17
18if type_name == 'CaptchaField':
19    id = 'key'
20
21if id is None:
22    id=context.generateUniqueId(type_name)
23
24if type_name is None:
25    raise Exception, 'Type name not specified'
26
27types_tool = getToolByName(context, 'portal_types')
28
29fti = types_tool.getTypeInfo(type_name)
30
31if not fti.queryMethodID('edit') and \
32   not fti.getActionObject('object/edit'):
33    state.setStatus('success_no_edit')
34
35if context.portal_factory.getFactoryTypes().has_key(type_name):
36    new_url = 'portal_factory/' + type_name + '/' + id
37    if state.getStatus() != 'success_no_edit':
38        new_url = new_url + '/edit'
39    state.set(status='factory', next_action='redirect_to:string:%s'%new_url)
40    # If there's an issue with object creation, let the factory handle it
41    return state
42else:
43    new_id = context.invokeFactory(id=id, type_name=type_name)
44    if new_id is None or new_id == '':
45       new_id = id
46    o=getattr(context, new_id, None)
47    tname = o.getTypeInfo().Title()
48    message = _(u'${tname} has been created.', mapping={u'tname' : tname})
49    transaction_note('Created %s with id %s in %s' % (o.getTypeInfo().getId(), new_id, context.absolute_url()))
50
51if o is None:
52    raise Exception
53
54if script_id:
55    state.setId(script_id)
56
57if message:
58    context.plone_utils.addPortalMessage(message)
59return state.set(context=o)
Note: See TracBrowser for help on using the repository browser.