creating instances of ZDiscussions programatically
I am having difficulty creating instances of ZDiscussions programatically. Creating instances from the ZMI works fine. But creating instances as an action and having it work automagically has proven to be a problem. Any help would be much appreciated.
Dennis Allison wrote:
I am having difficulty creating instances of ZDiscussions programatically. Creating instances from the ZMI works fine. But creating instances as an action and having it work automagically has proven to be a problem. Any help would be much appreciated.
Urm, it would help if you actually described the problems you're having ;-) cheers, Chris
Dennis Allison writes:
I am having difficulty creating instances of ZDiscussions programatically. Creating instances from the ZMI works fine. But creating instances as an action and having it work automagically has proven to be a problem. Do you already understand how creation from the ZMI works?
You have a form that collects parameters for the instance. The form then calls an action via the Web. ZPublisher automatically provides the parameters as needed. When you want to do this programmatically, you simply call the action with the correct parameters. It looks like: your_destination.manage_addProduct[your_product].the_action(parameters) "your_destination" is the ObjectManager (usually a folder) where the new instance shoult be created. "your_product" is the product which contains your class (probably "ZDiscussions" in your case). "the_action" is the action that would also be called by the ZMI. You need to know which parameters the action expects. This may be documented. If it is a DTML object, it will be "client" and "REQUEST". In the above case, "client" would be "your_destination.manage_addProduct[your_product]" and "REQUEST" the request object. When it is a DTML object (which is the default for ZClasses), then it may be a good idea to look into its definition. This may show you, how to get a bit leaner and more efficient code. Dieter
A later posting contains all the details... The ZDiscussions product does not inherit from ObjectManager--and I suspect it should. Is this my problem? I've looked at the implementation and am passing everything that appears to be needed... Thanks. On Fri, 26 Jul 2002, Dieter Maurer wrote:
Dennis Allison writes:
I am having difficulty creating instances of ZDiscussions programatically. Creating instances from the ZMI works fine. But creating instances as an action and having it work automagically has proven to be a problem. Do you already understand how creation from the ZMI works?
You have a form that collects parameters for the instance. The form then calls an action via the Web. ZPublisher automatically provides the parameters as needed.
When you want to do this programmatically, you simply call the action with the correct parameters. It looks like:
your_destination.manage_addProduct[your_product].the_action(parameters)
"your_destination" is the ObjectManager (usually a folder) where the new instance shoult be created. "your_product" is the product which contains your class (probably "ZDiscussions" in your case). "the_action" is the action that would also be called by the ZMI.
You need to know which parameters the action expects. This may be documented. If it is a DTML object, it will be "client" and "REQUEST". In the above case, "client" would be "your_destination.manage_addProduct[your_product]" and "REQUEST" the request object.
When it is a DTML object (which is the default for ZClasses), then it may be a good idea to look into its definition. This may show you, how to get a bit leaner and more efficient code.
Dieter
On Fri, 26 Jul 2002, Dennis Allison wrote:
A later posting contains all the details... The ZDiscussions product does not inherit from ObjectManager--and I suspect it should. Is this my problem? I've looked at the implementation and am passing everything that appears to be needed...
Applying Dieter's good advice, I still encounter problems. The ZClass with its Python base classes does not inherit from ObjectManager. When I try to add that in by reconstructing the class, I get the diagnostic appended below when I try to create the inner class whether it inherits from ObjectManager or not. What's happening? ----------------- Zope Error Zope has encountered an error while publishing this resource. Error Type: TypeError Error Value: loop over non-sequence Troubleshooting Suggestions The URL may be incorrect. The parameters passed to this resource may be incorrect. A resource that this resource relies on may be encountering an error. For more detailed information about the error, please refer to the HTML source for this page. If the error persists please contact the site maintainer. Thank you for your patience. Traceback (innermost last): File /var/zope/lib/python/ZPublisher/Publish.py, line 150, in publish_module File /var/zope/lib/python/ZPublisher/Publish.py, line 114, in publish File /var/zope/lib/python/Zope/__init__.py, line 159, in zpublisher_exception_hook (Object: methods) File /var/zope/lib/python/ZPublisher/Publish.py, line 98, in publish File /var/zope/lib/python/ZPublisher/mapply.py, line 88, in mapply (Object: manage_addZClass) File /var/zope/lib/python/ZPublisher/Publish.py, line 39, in call_object (Object: manage_addZClass) File /var/zope/lib/python/ZClasses/ZClassOwner.py, line 42, in manage_addZClass (Object: methods) File /var/zope/lib/python/ZClasses/ZClass.py, line 146, in manage_addZClass (Object: methods) File /var/zope/lib/python/ZClasses/ZClass.py, line 271, in __init__ (Object: ZDItem) TypeError: (see above)
participants (3)
-
Chris Withers -
Dennis Allison -
Dieter Maurer