Changes

Jump to: navigation, search

Zope HOWTO

195 bytes added, 6 years ago
no edit summary
== First Steps ==
First, you will need to emerge Zope{{Package|net-zope/zope}}:
<console>
# ##i## emerge --jobs=10 av zope
</console>
== Project Skeleton ==
{{fancynote|Note}} Zope should be used run by a regular user account, not as the root user.}}
The first step in using Zope is to ensure that you are using a regular user account. Create a new directory called ''<tt>zope_test</tt>'': <preconsole>$ ##bl## cd$ ##bl## mkdir zope_test</preconsole>
Now, enter the directory, and create an "instance", which is a set of files and directories that are used to contain a Zope project:
 <preconsole>$ ##bl## cd zope_test$ ##bl## /usr/lib/zope-2.13/bin/mkzopeinstance</preconsole>
You will see the following output, and will be prompted to answer a few questions:
 <preconsole>
Please choose a directory in which you'd like to install
Zope "instance home" files such as database files, configuration
Password: ****
Verify password: ****
 </preconsole>
Now, we will start our Zope instance:
<console>
$##bl## cd instance
$##bl## bin/runzope
</console>
<pre>$ cd instance$ bin/runzope</pre> Now that Zope is running, you can visit ''<tt>localhost:8080</tt> '' in your Web browser. You will see a nice introductory page to Zope.
If you now go to the ''<tt>localhost:8080/manage</tt> '' URL, you will be prompted to log in. Enter the username and password you specified. You are now logged in to the ZMI (Zope Management Interface.)
You can stop your application by pressing Control-C. In the future, you can start and stop your Zope instance using the following commands:
<preconsole>$ ##bl## zopectl start$ ##bl## zopectl stop</preconsole>
{{Note}} ''<tt>zopectl start</tt> '' will cause your instance to run in the background rather than consuming a shell console.
== First Project ==
=== <tt>etc/package-includes/example-configure.zcml</tt> ===
This file registers the ''<tt>example</tt> '' directory you created in ''<tt>lib/python</tt> '' as a ''package'', so that it is seen by Zope:
<preconsole>
<include package="example" />
</preconsole>
=== <tt>lib/python/example/interfaces.py</tt> ===
The following file defines the ''<tt>ITODO</tt> '' interface, and also uses some Zope Schema functions to define what kind of data we expect to store in objects that implement ''<tt>ITODO</tt>'':
<preconsole>
from zope.interface import Interface
from zope.schema import List, Text, TextLine, Int
daysleft = Int(title=u'Days left to complete', required=True)
description = Text(title=u'Description', required=True)
</preconsole>
=== <tt>lib/python/example/TODO.py</tt> ===
Now, we define ''<tt>TODO</tt> '' to be a ''persistent'' object, meaning it can be stored in the ZODB. We specify that it implements our previously-defined ''<tt>ITODO</tt> '' interface, and provide reasonable defaults for all values when we create a new TODO object: <preconsole>
from persistent import Persistent
from zope.interface import implements
daysleft = 0
description = u''
</preconsole>
=== <tt>lib/python/example/configure.zcml</tt> ===
Create an empty ''<tt>configure.zcml</tt> '' configuration file: <preconsole>
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:browser="http://namespaces.zope.org/browser">
</configure>
</preconsole>
== Debug Mode ==
We can test our first project by entering debug mode:
 <preconsole>$ ##bl## bin/zopectl debug
Starting debugger (the name "app" is bound to the top-level Zope object)
</preconsole>
Now, let's try creating a new TODO object and writing it out to a ZODB database:
 <preconsole>
>>> from ZODB import FileStorage, DB
>>> storage = FileStorage.FileStorage('mydatabase.fs')
>>> root[u'today'] = a
>>> transaction.commit()
</preconsole>
[[Category:HOWTO]]
Anonymous user

Navigation menu