[z3-checkins] r24989 - in z3/zopeweb/trunk/content/documentation: . z3tut/collector

baijum at codespeak.net baijum at codespeak.net
Sat Mar 25 05:42:51 CET 2006


Author: baijum
Date: Sat Mar 25 05:42:19 2006
New Revision: 24989

Modified:
   z3/zopeweb/trunk/content/documentation/z3tut/collector/configure.zcml
   z3/zopeweb/trunk/content/documentation/z3tut/collector/interfaces.py
   z3/zopeweb/trunk/content/documentation/z3tut/collector/ticket.py
   z3/zopeweb/trunk/content/documentation/z3tut/collector/ticketcollector.py
   z3/zopeweb/trunk/content/documentation/z3tut1.txt
Log:
Added two more sections to part1, and some code beautification.


Modified: z3/zopeweb/trunk/content/documentation/z3tut/collector/configure.zcml
==============================================================================
--- z3/zopeweb/trunk/content/documentation/z3tut/collector/configure.zcml	(original)
+++ z3/zopeweb/trunk/content/documentation/z3tut/collector/configure.zcml	Sat Mar 25 05:42:19 2006
@@ -15,11 +15,11 @@
         />
     <require
         permission="zope.ManageContent"
-        interface=".interfaces.ICollector"
+        set_schema=".interfaces.ICollector"
         />
     <require
         permission="zope.ManageContent"
-        set_schema=".interfaces.ICollector"
+        interface=".interfaces.ICollector"
         />
   </content>
 

Modified: z3/zopeweb/trunk/content/documentation/z3tut/collector/interfaces.py
==============================================================================
--- z3/zopeweb/trunk/content/documentation/z3tut/collector/interfaces.py	(original)
+++ z3/zopeweb/trunk/content/documentation/z3tut/collector/interfaces.py	Sat Mar 25 05:42:19 2006
@@ -36,7 +36,7 @@
 
 
 class ICollector(IContainer):
-    """The collector the base object. It can only
+    """Collector the base object. It can only
     contain ITicket objects."""
 
     def __setitem__(name, object):
@@ -53,7 +53,7 @@
 
 class ITicketContained(IContained):
     """Interface that specifies the type of objects that can contain
-    tickets."""
+    tickets.  So a ticket can only contain in a collector."""
 
     __parent__ = Field(
         constraint = ContainerTypesConstraint(ICollector))
@@ -61,7 +61,7 @@
 
 class ICommentContained(IContained):
     """Interface that specifies the type of objects that can contain
-    comments."""
+    comments.  So a comment can only contain in a ticket."""
 
     __parent__ = Field(
         constraint = ContainerTypesConstraint(ITicket))

Modified: z3/zopeweb/trunk/content/documentation/z3tut/collector/ticket.py
==============================================================================
--- z3/zopeweb/trunk/content/documentation/z3tut/collector/ticket.py	(original)
+++ z3/zopeweb/trunk/content/documentation/z3tut/collector/ticket.py	Sat Mar 25 05:42:19 2006
@@ -7,7 +7,7 @@
 from interfaces import ITicketContained
 
 class Ticket(BTreeContainer, Contained):
-    """A simple implementation of a ticket.
+    """A simple implementation of a ticket using B-Tree Containers.
 
     Make sure that the ``Ticket`` implements the ``ITicket`` interface::
 

Modified: z3/zopeweb/trunk/content/documentation/z3tut/collector/ticketcollector.py
==============================================================================
--- z3/zopeweb/trunk/content/documentation/z3tut/collector/ticketcollector.py	(original)
+++ z3/zopeweb/trunk/content/documentation/z3tut/collector/ticketcollector.py	Sat Mar 25 05:42:19 2006
@@ -4,7 +4,7 @@
 from interfaces import ICollector
 
 class Collector(BTreeContainer):
-    """A very simple implementation of a collector using B-Tree Containers
+    """A simple implementation of a collector using B-Tree Containers.
 
     Make sure that the ``Collector`` implements the ``ICollector``
     interface::
@@ -18,9 +18,9 @@
       >>> collector = Collector()
       >>> collector.description
       u''
-      >>> collector.description = u'Message Collector Description'
+      >>> collector.description = u'Ticket Collector Description'
       >>> collector.description
-      u'Message Collector Description'
+      u'Ticket Collector Description'
     """
 
     implements(ICollector)

Modified: z3/zopeweb/trunk/content/documentation/z3tut1.txt
==============================================================================
--- z3/zopeweb/trunk/content/documentation/z3tut1.txt	(original)
+++ z3/zopeweb/trunk/content/documentation/z3tut1.txt	Sat Mar 25 05:42:19 2006
@@ -22,13 +22,13 @@
   # ./configure --with-python=/path/to/python2.4
   # make install
 
-We recommend binary `setup for windows`_, you may go for source
-installation, if required.
+I recommend binary setup for win32_, you may go for source
+installation, if required. 
 
 If you cannot install Zope3, see the `detailed instruction`_.
 
 .. _Python 2.4.2: http://www.python.org/ftp/python/2.4.2/Python-2.4.2.tar.bz2
-.. _setup for windows: http://www.zope.org/Products/Zope3/3.2.0final/Zope-3.2.0.win32-py2.4.exe
+.. _win32: http://www.zope.org/Products/Zope3/3.2.0final/Zope-3.2.0.win32-py2.4.exe
 .. _detailed instruction: install.html
 
 
@@ -117,25 +117,16 @@
   var:
   Data.fs  Data.fs.index  Data.fs.lock  Data.fs.tmp  README.txt
 
-.. sidebar:: Instance utility scripts
 
-  As you can see, the ``bin`` directory contains few scripts like
-  ``runzope``, ``test`` etc.
-
-  You can controll zope from ``zopectl``, you will get a prompt
-  from where you can start,stop,restart zope.
-
-  Some scripts are only specific to Windows.
-
-
-The `bin` directory contains few scripts like `runzope`, `test`
-etc. Zope saving all data in `var` directory.  Backup this directory
-regularly.  If ``Data.fs`` is missing, it will be automatically created
-when you run zope again. In `etc` you can see some configuration
-files.  In ``etc/zope.conf`` you can edit port numbers of various
-servers. In ``lib/python`` you can place your Zope3 packages.  By
-default this won't be in your Python path. You can also place your
-package in any standard Python path. 
+As you can see, the ``bin`` directory contains few scripts like
+``runzope``, ``test`` etc.  Some scripts are only specific to Windows.
+Zope saves all data in `var` directory.  Backup this directory
+regularly.  If ``Data.fs`` is missing, it will be automatically
+created when you run zope again. In `etc` you can see some
+configuration files.  In ``etc/zope.conf`` you can edit port numbers
+of various servers.  In ``lib/python`` you can place your Zope3
+packages.  By default this won't be in your Python path.  You can also
+place your packages in any standard Python path.
 
 
 The ZMI
@@ -166,8 +157,8 @@
 .. sidebar:: Extreme Programming
 
   We will be using Extreme Programming style terminologies
-  through this tutorial.  We recommend you to use this
-  (or similar) development process in your workplace.  Zope 3 has taken
+  through this tutorial.  I recommend you to use this  (or similar)
+  development process in your workplace.  Zope 3 has taken
   lots of ideas from `Extreme Programming`_.
 
 To learn Zope 3 application development we will be using a
@@ -189,12 +180,12 @@
 Interfaces
 ----------
 
-The first thing you have to do in coding to finalize the initial
-intraces of content objects, of course you can evolve it later.
-This is something similar to table design, if you are using
-RDBMS, but not exactly the same, you will understand why it's not.
+The first thing you have to do is to finalize the initial intraces of
+content objects, of course you can evolve it later.  This is something
+similar to table design, if you are using RDBMS, but not exactly the
+same, you will understand why it's not.
 
-As I said earlier you acn place your packages in ``lib/python``
+As I said earlier you can place your packages in ``lib/python``
 directory.  So create ``lib/python/collector``, and don't forget
 to add ``__init__.py`` (empty file) to make it a Python package.
 
@@ -239,7 +230,7 @@
 
 
   class ICollector(IContainer):
-      """The collector the base object. It can only
+      """Collector the base object. It can only
       contain ITicket objects."""
 
       def __setitem__(name, object):
@@ -256,7 +247,7 @@
 
   class ITicketContained(IContained):
       """Interface that specifies the type of objects that can contain
-      tickets."""
+      tickets.  So a ticket can only contain in a collector."""
 
       __parent__ = Field(
           constraint = ContainerTypesConstraint(ICollector))
@@ -264,7 +255,7 @@
 
   class ICommentContained(IContained):
       """Interface that specifies the type of objects that can contain
-      comments."""
+      comments.  So a comment can only contain in a ticket."""
 
       __parent__ = Field(
           constraint = ContainerTypesConstraint(ITicket))
@@ -349,7 +340,7 @@
 To run the unit test::
 
   $ cd $HOME/myzope/etc
-  $ ../bin/test -vpu --dir boom
+  $ ../bin/test -vpu --dir collector
 
 Of cource now all tests should fail.
 
@@ -357,11 +348,240 @@
 Implementation
 --------------
 
+As you can see in the unit test module, collector is going to be
+implemented in ticketcollector.py::
+
+  from zope.interface import implements
+  from zope.app.container.btree import BTreeContainer
+
+  from interfaces import ICollector
+
+  class Collector(BTreeContainer):
+      """A simple implementation of a collector using B-Tree Containers.
+
+      Make sure that the ``Collector`` implements the ``ICollector``
+      interface::
+
+        >>> from zope.interface.verify import verifyClass
+        >>> verifyClass(ICollector, Collector)
+        True
+    
+      Here is an example of changing the description of the collector::
+
+        >>> collector = Collector()
+        >>> collector.description
+        u''
+        >>> collector.description = u'Ticket Collector Description'
+        >>> collector.description
+        u'Ticket Collector Description'
+      """
+
+      implements(ICollector)
+
+      description = u''
+
+Similarly ticket.py::
+
+  from zope.interface import implements
+  from zope.interface import classProvides
+  from zope.app.container.btree import BTreeContainer
+  from zope.app.container.contained import Contained
+
+  from interfaces import ITicket
+  from interfaces import ITicketContained
+
+  class Ticket(BTreeContainer, Contained):
+      """A simple implementation of a ticket using B-Tree Containers.
+
+      Make sure that the ``Ticket`` implements the ``ITicket`` interface::
+
+        >>> from zope.interface.verify import verifyClass
+        >>> verifyClass(ITicket, Ticket)
+        True
+
+      Here is an example of changing the summary and description of the ticket::
+
+        >>> ticket = Ticket()
+        >>> ticket.summary
+        u''
+        >>> ticket.description
+        u''
+        >>> ticket.summary = u'Ticket Summary'
+        >>> ticket.description = u'Ticket Description'
+        >>> ticket.summary
+        u'Ticket Summary'
+        >>> ticket.description
+        u'Ticket Description'
+      """
+
+      implements(ITicket, ITicketContained)
+
+      summary = u''
+      description = u''
+
+Similarly comment.py::
+
+  from zope.interface import implements
+
+  from interfaces import IComment
+  from interfaces import ICommentContained
+  from zope.app.container.contained import Contained
+
+  class Comment(Contained):
+      """A simple implementation of a comment.
+
+      Make sure that the ``Comment`` implements the ``IComment`` interface::
+
+        >>> from zope.interface.verify import verifyClass
+        >>> verifyClass(IComment, Comment)
+        True
+
+      Here is an example of changing the body of the comment::
+
+        >>> comment = Comment()
+        >>> comment.body
+        u''
+        >>> comment.body = u'Comment Body'
+        >>> comment.body
+        u'Comment Body'
+      """
+
+      implements(IComment, ICommentContained)
+
+      body = u""
+
 
 Configuration
 -------------
 
+We have written intefaces and its implemenations, now how to bind this
+with Zope 3 framework.  We will use Zope Configuration Markup Language
+(ZCML) based configuaration file for this.
+
+This is our configure.zcml::
+
+  <configure
+      xmlns="http://namespaces.zope.org/zope">
+
+    <interface 
+        interface=".interfaces.ICollector" 
+        type="zope.app.content.interfaces.IContentType"
+        /> 
+
+    <content class=".ticketcollector.Collector">
+      <implements
+          interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
+          />
+      <implements
+          interface="zope.app.container.interfaces.IContentContainer" 
+          />
+      <require
+          permission="zope.ManageContent"
+          set_schema=".interfaces.ICollector"
+          />
+      <require
+          permission="zope.ManageContent"
+          interface=".interfaces.ICollector"
+          />
+    </content>
+
+    <interface 
+        interface=".interfaces.ITicket" 
+        type="zope.app.content.interfaces.IContentType"
+        /> 
+
+    <content class=".ticket.Ticket">
+      <implements
+          interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
+          />
+      <implements
+          interface="zope.app.container.interfaces.IContentContainer" 
+          />
+      <require
+          permission="zope.ManageContent"
+          set_schema=".interfaces.ITicket"
+          />
+      <require
+          permission="zope.ManageContent"
+          interface=".interfaces.ITicket"
+          />
+    </content>
+
+    <interface 
+        interface=".interfaces.IComment" 
+        type="zope.app.content.interfaces.IContentType"
+        /> 
+
+    <content class=".comment.Comment">
+      <implements
+          interface="zope.app.annotation.interfaces.IAttributeAnnotatable"
+          />
+      <require
+          permission="zope.ManageContent"
+          set_schema=".interfaces.IComment"
+          />
+      <require
+          permission="zope.ManageContent"
+          interface=".interfaces.IComment"
+          />
+    </content>
+
+    <include package=".browser" />
+
+  </configure>
+
 
 Running application
 -------------------
 
+Before running the applcation we will add one some view for adding
+Collector.  We will go in to more details in the next part.
+
+Create a `browser` directory and under that, a new `configure.zcml`
+file::
+
+  <configure
+      xmlns="http://namespaces.zope.org/browser">
+
+    <addMenuItem
+        class="collector.ticketcollector.Collector"
+        title="Collector"
+        description="A Collector"
+        permission="zope.ManageContent"
+        />
+
+  </configure>
+
+The "class" attribute specifies the module path for the class, a
+leading dot means to make the import relative to the package
+containing the ZCML file. Therefore in this case Zope will import the
+collector.ticketcollector module, then import "Collector" from that module. 
+
+The "title" attribute provides the title to display in the add menu. 
+
+The "permission" attribute is used to describe what permission is
+required for a person to be able to add one of these objects. The
+"zope.ManageContent" permission means that the user can add, remove,
+and modify content (the "admin" user you created while making the
+instance is one such user). 
+
+We need to tell Zope to read our ZCML file, and the easiest way to do
+that is to put a "slug" in the $HOME/myzope/etc/package-includes/
+directory. A "slug" is a ZCML file that just includes another
+file. Here's what our slug should look like (save it as
+"collector-configure.zcml")::
+
+  <include package="collector" />
+
+Now if we start Zope back up, we can go to the ZMI and add our content
+type by clicking on "Add Collector" and entering a name for our
+object; name it "MyCollector".
+
+Now restart Zope and visit http://localhost:8080
+You can add collector from menu.
+
+.. Note::
+
+  Some part of this tutorial is taken from Benji York's Zope 3 Quick
+  Start Guide, http://www.benjiyork.com/quick_start/
+  "Benji York (http://benjiyork.com)"


More information about the z3-checkins mailing list