[Zope] Adding instance of ZDiscussions programmatically

Dennis Allison allison@sumeru.stanford.EDU
Sun, 28 Jul 2002 19:30:49 -0700


> Dennis Allison writes:
>  > Chris pointed out my initial question was pretty vague and my response to him was 
>  > not much better.  Here's a more specific statement--
>  > 
>  > I want to add instances of ZDTopics (that is ZDiscussion Topics) programmatically.
>  > 
>  > I've constructed a DTML Method per the How-To:
>  > ...
>  > <dtml-with "manage_addProduct['ZDTopic']">
>  > ....
>  > | Error Type: AttributeError
>  > | Error Value: ZDTopic
>  > ...
>  > |   File /var/zope/lib/python/App/Product.py, line 66, in _product
>  > |     (Object: Products)
>  > | AttributeError: (see above)
> Are you sure, the product is "ZDTopic" and not "ZDiscussion"?
> As the last few traceback lines show, the problem comes from
> product resolution.
> 

You are right, of course, brought on by the fact that the create 
tab is for creating a "ZDiscussions Topic".  Unfortunately, I still have
a problem.  

using Python rather than DTML, I wrote

container.manage_addProduct['ZDiscussions']

which gives me the dispatcher object as I would have expected.  Now, the 
ZDiscussions product a ZClass with python base classes (ZDBase).  The 
inheritances seem to be correct, but when I write

container.manage_addProduct['ZDiscussions'].manage_addZDTopic( id, title= ... )

I get:
Error Type: AttributeError
Error Value: manage_addZDTopic

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: footest)
  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: pyc2)
  File /var/zope/lib/python/ZPublisher/Publish.py, line 39, in call_object
    (Object: pyc2)
  File /var/zope/lib/python/Shared/DC/Scripts/Bindings.py, line 252, in __call__
    (Object: pyc2)
  File /var/zope/lib/python/Shared/DC/Scripts/Bindings.py, line 283, in _bindAndExec
    (Object: pyc2)
  File /var/zope/lib/python/Products/PythonScripts/PythonScript.py, line 302, in _exec
    (Object: pyc2)
    (Info: ({'script': <PythonScript instance at 932bb58>, 'context': <Folder instance at 8f75a78>, 'container': <Folder instance at 8f75a78>, 'traverse_subpath': []}, (), {}, None))
  File Script (Python), line 6, in pyc2
  File /var/zope/lib/python/AccessControl/ZopeGuards.py, line 47, in guarded_getattr
AttributeError: (see above)

which has me baffled.  I have looked at the code in ZDBase and the
manageZDTopic() method is there.

The form manage_add in the Control_Panel/Products begins for 
the product is 

<!--#with "ZDTopic.createInObjectManager(REQUEST['id'], REQUEST)"-->

What does this translate to in terms of a python script.  Clearly there is something 
more going on here...

container.manage_addProduct['ZDiscussions'].ZDTopic.createInObjectManager(container.REQUEST['id'], container.REQUEST)

seems to do the job.  Thanks for your help.