[Zope-Checkins] SVN: Zope/branches/jim-fix-zclasses/lib/python/ZClasses/ZClass.txt Created a basic ZClass test. It still isn't used, because the

Jim Fulton jim at zope.com
Mon Feb 7 07:36:04 EST 2005


Log message for revision 29070:
  Created a basic ZClass test. It still isn't used, because the
  persistent meta class hasn't been integrated yet.
  

Changed:
  A   Zope/branches/jim-fix-zclasses/lib/python/ZClasses/ZClass.txt

-=-
Added: Zope/branches/jim-fix-zclasses/lib/python/ZClasses/ZClass.txt
===================================================================
--- Zope/branches/jim-fix-zclasses/lib/python/ZClasses/ZClass.txt	2005-02-07 12:36:01 UTC (rev 29069)
+++ Zope/branches/jim-fix-zclasses/lib/python/ZClasses/ZClass.txt	2005-02-07 12:36:03 UTC (rev 29070)
@@ -0,0 +1,70 @@
+Basic ZClass Tests
+==================
+
+We can create ZClasses from Python, It's a bit complicated, as
+ZClasses were designed mainly to be used from the web.
+
+To do anything, we need a working Zope object space:
+
+  >>> from ZODB.DemoStorage import DemoStorage
+  >>> s = DemoStorage()
+  >>> import ZODB.DB
+  >>> db = ZODB.DB(s)
+  >>> conn = db.open()
+  >>> from OFS.Application import Application
+  >>> app = Application()
+  >>> conn.root()['Application'] = app
+  >>> from OFS.Application import initialize
+  >>> initialize(app)
+
+Once we have an object space, we need to create a product to hold the ZClass:
+
+  >>> app.Control_Panel.Products.manage_addProduct('test', '')
+  >>> test = app.Control_Panel.Products['test']
+
+Then we can create the ZClass in the product:
+
+  >>> test.manage_addZClass('C', zope_object=True,  CreateAFactory=True)
+
+Having create a ZClass, we can create an instance:
+
+  >>> c = test.C()
+  >>> c._setId('c')
+  >>> app._setObject('c', c)
+  'c'
+
+Now, ZClass instances aren't very interesting by themselves.  We can
+give them data by defining property sheets:
+
+  >>> test.C.propertysheets.common.manage_addCommonSheet('basic', '')
+  >>> test.C.propertysheets.common['basic'].manage_addProperty(
+  ...     'x', 'hee ', 'string')
+  >>> app.c.x
+  'hee '
+  >>> test.C.propertysheets.common['basic'].manage_addProperty('y', 42, 'int')
+  >>> app.c.y
+  42
+
+Of course, we can change the data:
+
+  >>> app.c.x = 'hi '
+  >>> app.c.y = 3
+  >>> app.c.x, app.c.y
+  ('hi ', 3)
+
+We can also add methods, such as Python scripts:
+
+  >>> test.C.propertysheets.methods.manage_addProduct[
+  ...      'PythonScripts'].manage_addPythonScript('eek')
+  ''
+  >>> test.C.propertysheets.methods['eek'].ZPythonScript_edit('',
+  ...      'return container.x * container.y')
+
+  >>> app.c.eek()
+  'hi hi hi '
+
+We're done, so clean up:
+
+  >>> import transaction
+  >>> transaction.commit()
+  >>> db.close()


Property changes on: Zope/branches/jim-fix-zclasses/lib/python/ZClasses/ZClass.txt
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope-Checkins mailing list