[Zope] example from ZODB How-To

Jens Linge linge@embl-heidelberg.de
Tue, 14 Dec 1999 18:57:30 +0100


Dear all,

I tried the example MySimpleZODBApp class from the ZODB how-to
(http://www.zope.org/Members/michel/HowTos/ZODB-How-To), but couldn't
get it running. The Python code for the external method is:

import Persistence
import ZODB

class Person(Persistence.Persistent):
    """A Persistent Person"""
    def __init__(self, name, age):
        self.name = name
        self.age = age
        
class MySimpleZODBApp:
    """ A simple application object that manages persistent
    object's of the 'Person' class. """
    def __init__(self, file='Data.fs'):
        """ Create a database, connect to it and get the root
        object out of it.  """
        self.db = ZODB.DB(ZODB.FileStorage(file))
        self.connection = self.db.open()
        self.root = self.connection.root()

        if not len(root):
            self.root['billy'] = Person('Billy', 77)
            
            # normally Zope will handle transactions,
            # but in this special case, we need to 
            # commit the transaction to save the new
            # persistent object
            
            get_transaction().commit()

    def addPerson(self, name, age):
        """ Adds a 'Person' to the database """
        if self.root.has_key(name):
            raise 'PersonAllReadyExists', "They're allready there"
        else:
            self.root[name] = Person(name, age)
            get_transaction().commit()
            
    def delPerson(self, name):
        """ Deletes a 'Person' from the database """
        if self.root.has_key(name):
            del self.root[name]
            get_transaction().commit()
        else:
            raise 'NoSuchPerson', 'Who?'


In the line:
self.db = ZODB.DB(ZODB.FileStorage(file))
I added a missing ) in the end.

I used the following external method:

def createDB(self, REQUEST):
    """
    create an instance of MySimpleZODBApp
    """
    testDB = MySimpleZODBApp()


I called it from zope via dtml:
<dtml-var "createDB(REQUEST)">

However, when loading the page, I get the following traceback:

Zope has encountered an error while publishing this resource. 

                       Error Type: TypeError
                       Error Value: call of non-function (type module)


Traceback (innermost last):
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Publish.py, line
214, in publish_module
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Publish.py, line
179, in publish
  File /local/zope/Zope-2.0.1-linux2-x86/lib/python/Zope/__init__.py,
line 201, in zpublisher_exception_hook
    (Object: ElementWithAttributes)
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Publish.py, line
165, in publish
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/mapply.py, line
160, in mapply
    (Object: copy_of_index_html)
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/ZPublisher/Publish.py, line
102, in call_object
    (Object: copy_of_index_html)
  File /local/zope/Zope-2.0.1-linux2-x86/lib/python/OFS/DTMLDocument.py,
line 166, in __call__
    (Object: copy_of_index_html)
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/DocumentTemplate/DT_String.py,
line 502, in __call__
    (Object: copy_of_index_html)
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/DocumentTemplate/DT_Util.py,
line 321, in eval
    (Object: createDB(REQUEST))
  File <string>, line 0, in ?
  File
/local/zope/Zope-2.0.1-linux2-x86/lib/python/Products/ExternalMethod/ExternalMethod.py,
line 253, in __call__
    (Object: createDB)
    (Info: ((<h3>form</h3><table> ...
... (several lines deleted)
... </table>,), {}, None))
  File /local/zope/zope/Extensions/booking.py, line 143, in createDB
    (Object: ElementWithAttributes)
  File /local/zope/zope/Extensions/booking.py, line 31, in __init__
TypeError: (see above)


line 143 is the line where I instantiate MySimpleZODBApp:
MSTEST = MySimpleZODBApp()


line 31 is the line in the constructor of MySimpleZODBApp:
self.db = ZODB.DB(ZODB.FileStorage(file))



I don't know what went wrong. Did anyone try this example? I had a quick
look at the sources, but couldn't figure out the error.
I also tried it on a different machine running Zope 2.0, but got the
same traceback.

Thank you in advance.

Jens


-- 
Jens Linge            phone: +49 6221 387140
EMBL, Nilges Group    fax:   +49 6221 387517 
Meyerhofstr. 1        www:   http://www.linge.de
D-69012 Heidelberg    priv:  +49 6221 169139