creating ZClasses with external method
I still cannot create ZClasses with an external method (using aquisition) Since I can do it with ZPublisher.Client and by typing in a URL into my browser, but not via an external method, this is really seeming like a bug. Should I report this to Collector? For instance, I can do it this way:
from ZPublisher.Client import Function f = Function('http://localhost/zope2/alex/manage_addProduct/Foo/foo?id=hello', method='GET', username='...', password='...') apply(f)
I now have successfully created a foo type ZClass named 'hello' in the Folder alex/. I also get a 302 http error back from apply(), so is this is not the correct way to be programatically creating ZClasses? What is the recommendeed way? But cannot do it this way. If I create an external method with one line like so: def hello(self): self.manage_addProduct.Foo.foo(id='helloworld') Now if I visit http://localhost/zope2/alex/hello I get Error Type: AttributeError Error Value: Foo Traceback (innermost last): File /usr/share/Zope-2.0.0a3-src/lib/python/ZPublisher/Publish.py, line 256, in publish_module File /usr/share/Zope-2.0.0a3-src/lib/python/ZPublisher/Publish.py, line 161, in publish File /usr/share/Zope-2.0.0a3-src/lib/python/ZPublisher/mapply.py, line 154, in mapply (Object: hello) File /usr/share/Zope-2.0.0a3-src/lib/python/ZPublisher/Publish.py, line 98, in call_object (Object: hello) File /usr/share/Zope-2.0.0a3-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 259, in __call__ (Object: hello) (Info: ((<Application instance at 81c0cd0>,), {}, None)) File /usr/share/Zope-2.0.0a3-src/lib/python/Products/ExternalMethod/ExternalMethod.py, line 247, in __call__ (Object: hello) (Info: ((<Application instance at 81c0cd0>,), {}, None)) File /usr/share/zope/Extensions/hai.py, line 9, in hai (Object: ApplicationDefaultPermissions) AttributeError: (see above) Alex Rice | alrice@swcp.com | http://www.swcp.com/~alrice Current Location: N. Rio Grande Bioregion, Southwestern USA
[answering my own question, and then asking another :-)] On Sun, 4 Jul 1999 17:55:14 -0600 (MDT), Alex Rice <alrice@swcp.com> said: Alex> I still cannot create ZClasses with an external method (using Alex> aquisition) Since I can do it with ZPublisher.Client and by typing Alex> in a URL into my browser, but not via an external method, this is Alex> really seeming like a bug. Should I report this to Collector? <snip> It looks so easy in retrospect :-) This method below works a like a charm. I adapted this from Brian Lloyd's post today to zope-dev (subject: ZClasses instances become detached from class). def addFoo(self, id='a_obj', REQUEST=None): """ """ # Get the actual destination object, using the this() # method, to be sure we get it in the right context.. self=self.this() # Create the new instance newob=self.Control_Panel.Products.Foo.foo(id) # redundant? newob.id=id # Set properties based on the contents of the Add form newob.propertysheets.info.manage_changeProperties(REQUEST) # Add the new instance to the target object self._setObject(id, newob) return 'OK!' Question: why the heck does one need to call self=self.this()? In what cases does it make a difference? That's just weird. Is this() def'd in SimpleItem.py? Alex Rice
participants (1)
-
Alex Rice