[Zope] ZClass, Base Classes and logic (QUEST)

Oscar Picasso picasso@videotron.ca
Thu, 09 Mar 2000 14:51:59 -0500


Hi,

Most of the time when someone complains about DTML syntax or the learning curve
and so on, the answer is we should code our logic in python if we know this
language. That's what I am trying to do because I love Python.

However, many times I don't know how to import my logic in Zope. 

example:

I wrote a very simple module MyTest.py:
##################################
class SuperClass:
	def __init__(self):
		self.a='This is a in SuperClass'

class MyClass(SuperClass):
	def __init__(self):
		SuperClass.__init__(self)
		self.b='This is b in Myclass'
##################################
In the python interpreter I do the following things:
>>>import MyTest
>>>import MyTest.MyClass
>>>t=MyTest.MyClass.MyClass()
>>>t.a
'This is a in SuperClass'
>>>t.b
'This is b in Myclass'

That's what I expected. Now I intall the package in zope.  I make a ZClass which
only Base class in MyClass. Its metatype is MyClassClass, so it appears on the
popup menu near the Add button.

But when I try to add an instance I get the following message:

Error Type: TypeError
          Error Value: unbound method must be called with class instance 1st
          argument

I guess that the problem is the line
	SuperClass.__init__(self)

==>however I don't understand why it works fine with the python interpreter and
why not in Zope.

Others behaviors of Zope:
suppose i add the following line in the MyClass __init__ function:
self.d='I am d'

No problem when I run it with the interpreter:
	>>>t.d
	'I am d'

In zope:
	<dtml-var "MyClassInstance.d"> 
renders:
	Error Type: AttributeError
          	Error Value: d

I get the right value of d only with the new instances of MyClass. On the other
hand if MyClass has a property sheet, all the instances are updated if change
the property sheet.

==>So again, why these differences in the behavior of ZClass instances depending
of which part we modify (the python Base Class or the Zope ZClass)?

I really love Zope but I prefer code in python. However I hit often the wall
when I try to put the pieces together. I think that speaking about
documentation : clear API docs would be, for me the most important.
What behavior could I expect from the differents parts of Zope. 

Example of docs I find useful with other 'languages':
Python Library Reference
Java API documentation