[Zope] Re: creating ZClasses with external method

Alex Rice alrice@swcp.com
Mon, 12 Jul 1999 16:23:55 -0600 (MDT)


[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