[Zope-CMF] how to get the object created by invokeFactory

Grégoire Weber gregoire.weber@switzerland.org
Tue, 03 Jul 2001 13:03:38 +0200


Hi all!

I'd like to programmatically add a topic by using a 
Python Script and it seems that I am on the right way 
but there is one problem left:

-------------------------------------------------------
## Script (Python) "invokeTopic"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=REQUEST, RESPONSE, title=None, description=None, id=None
##title=
##
context.invokeFactory('Topic', id)
obj=######## how do I get the obj if the newly created topic with the id
'id'? 
obj.edit(title='empty title', description='empty description')
obj.addCriteria(field='Subject', criteria_type='String Criterion')

RESPONSE.redirect('%s/topic_view' % obj.absolute_url())
-------------------------------------------------------

What I have tried:
1) # invokeFactor returns None (argh!)
   obj = context.invokeFactory('Topic', id)

2) # could not import HTTPRequest
   from HTTPRequest.HttpRequest import resolve_url
   obj = resolve_url(context.absolute_url()+'/'+id) 

I've took a look at the management screens also and I have 
seen that invokeFactory is called by DTML methods which do 
a redirect to one of the objects method like this:
   RESPONSE.redirect('%s/topic_view' % context.absolute_url())

The following method calls (e.g. topic_editTopic) is then
able to refer to context. But in my case the context is the 
directory containing the topic.

I am sure it's only a small piece of the puzzle I am missing.

Can somebody help me?

Thanks, Greg
_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org