[Zope-dev] urg

Tom Deprez tom.deprez@uz.kuleuven.ac.be
Tue, 07 Mar 2000 12:29:01 +0100


>I think you should not use an external method, but rather create a
>Python class that subclasses whatever you want to subclass and then
>defines a new manage_afterAdd that implements your behavior.  I don't
>think external methods are ideal at all for this kind of development. 
>This requires either reverse engineering existing Zope products or
>culling the list for this wisdom, there really isn't any formal recipie
>for this kind of thing.  This isn't necessarily a documetation issue,
>for altough we can document interfaces and product conventions (which we
>are working on), we cannot entirely document every issue concerning
>engineering software in python.

Why can't I use a ZClass for this, like I'm doing now? I don't know
anything about Python, so I really don't know how to start with a Python
class that subclasses...
I only want to have a ZClass which changes a property when an instance is
added, but also when it's moved (cut, paste). The only reason why I'm
working with an external method is because people told me about the
manage_afterAdd method. What is at the moment the only way to achieve the
thing I want (ie. a property that is updated when an instance is moved eg
from one folder to another).

Is their another way to now when a ZClass instance is updated or moved?
Why I want to do this? This is what I'm trying to make:

A knowledge base system which automatically cataloges itself into the
catalog (so they should descent from CatalogAware). A KBItem can only exist
in a KBFolder. The KBItem is cataloged on a property of the KBItem. The
property will contain a string with the names of its parent KBFolder,
parent-parent KBFolder, etc. This way, no special handling has to be done
to create certain KB categories. The KBFolders itself are the categories.
One problem to achieve this is to find a way how the 'cataloged property'
of a KBItem instance can be updated when it is added and moved.

In fact, in my idea, just a simple KB product, but it looks like it is hard
to create.

>> Thanks to another email, I could solve this 'unbound method-error' with the
>> following line :
>> 
>> CatalogAware.manage_afterAdd.im_func(self,item,container)
>
>Off the top of my head, I don't know why you have to do this.  Whether
>this is an artifact of developing with ZClasses and External Methods I
>couldn't tell you either.  But I do know that when developing a pure
>python class this does not need to happen and is probably a bad idea to
>get into the habit.

mmm... here is the mail where I got this im_func from: 

Tom, I haven't done exactly what you're trying to do -- extend CatalogAware
methods in a ZClass -- but I have a similar kinds of method extension in a
Python product class.

  # Only index if nextEventTime returns something
  def index_object(self):
    if self.nextEventTime() is not None:
        CatalogAware.index_object.im_func(self)
        # see Python Reference Manual "The standard type hierarchy"
        # for the built-in type im_func

Actually this code came from Martijn Pieters. He explained:

"""
im_func is a part of Python introspection. It is the pure function
definition of a class, not bound to that class, so I can pass in an
alternate self.

I am trying to call a superclass method here, and normally
CatalogAware.index_object() would suffice. But because of Extension Classes,
Python gets confused as to what is a class method, and what is a regular
function. It will accuse me of calling an unbound method, which of course I
am not. I circumvent this by calling the unbound function, and passing in
self explicitly.
"""

I don't know if this applies to your case.

Regards, Tom.