[Zope-CMF] how to get the object created by invokeFactory
Grégoire Weber
gregoire.weber@switzerland.org
Tue, 03 Jul 2001 16:38:34 +0200
thanks a lot Seb, it was the missing point to success!
> > context.invokeFactory('Topic', id)
> > obj=### how do I get the obj if the newly created topic with the id?=
>
> This should work:
> obj = context[id]
See code below.
> At 15:18 03.07.01 +0100, Chris Whiters wrote:
> What would solve the problem properly is for invokeFactory to
> return the new object. If it doesn't already, ti should ;-)
It does definitively not and it would be a good thing if it
would do!
Greg
-------------------------------------------------------
## Script (Python) "invokeTopic"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST, RESPONSE, id, subj=None, title='', description='',
acquireCriteria='1'
##title=add a topic with 'id' and a string criteria value of 'subj' or 'id'
for 'Subject' programmatically
##
# instanate a topic with a id of 'id'
context.invokeFactory('Topic', id)
# get id of topic (thanks seb!)
obj=context[id]
# title and description of topic
obj.edit(acquireCriteria=acquireCriteria,
title=title,
description=description)
# add a string criteria for 'Subject'
obj.addCriteria(field='Subject',
criteria_type='String Criterion')
# set the value of the 'Subject' criteria
if subj is None: subj = id
crit=obj.getCriterion('crit__Subject')
crit.edit(value=subj)
# redirect to the topics page
RESPONSE.redirect(obj.absolute_url())
-------------------------------------------------------
_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org